diff --git a/context.go b/context.go index ed88bb9f..a1d34b79 100644 --- a/context.go +++ b/context.go @@ -686,7 +686,7 @@ func (c *Context) GetRawData() ([]byte, error) { // SetCookie adds a Set-Cookie header to the ResponseWriter's headers. // The provided cookie must have a valid Name. Invalid cookies may be // silently dropped. -func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool, sameSite string) { +func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, sameSite string, secure, httpOnly bool) { if path == "" { path = "/" } @@ -696,9 +696,9 @@ func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, MaxAge: maxAge, Path: path, Domain: domain, + SameSite: sameSite, Secure: secure, HttpOnly: httpOnly, - SameSite: sameSite, }) } diff --git a/context_test.go b/context_test.go index 6fc935d1..d7833e4c 100644 --- a/context_test.go +++ b/context_test.go @@ -579,14 +579,14 @@ func TestContextPostFormMultipart(t *testing.T) { func TestContextSetCookie(t *testing.T) { c, _ := CreateTestContext(httptest.NewRecorder()) - c.SetCookie("user", "gin", 1, "/", "localhost", true, true) - assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; SameSite=Lax; Secure", c.Writer.Header().Get("Set-Cookie")) + c.SetCookie("user", "gin", 1, "/", "localhost", "Lax", true, true) + assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; SameSite=Lax; HttpOnly; Secure", c.Writer.Header().Get("Set-Cookie")) } func TestContextSetCookiePathEmpty(t *testing.T) { c, _ := CreateTestContext(httptest.NewRecorder()) - c.SetCookie("user", "gin", 1, "", "localhost", true, true) - assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; HttpOnly; SameSite=Lax; Secure", c.Writer.Header().Get("Set-Cookie")) + c.SetCookie("user", "gin", 1, "", "localhost", "Lax", true, true) + assert.Equal(t, "user=gin; Path=/; Domain=localhost; Max-Age=1; SameSite=Lax; HttpOnly; Secure", c.Writer.Header().Get("Set-Cookie")) } func TestContextGetCookie(t *testing.T) {