mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
Merge pull request #74 from infinite-iroha/break/v1-feat-add-samesite
Some checks are pending
Go Test / test (push) Waiting to run
Some checks are pending
Go Test / test (push) Waiting to run
feat(cookie): add SameSite support to SetCookie method
This commit is contained in:
commit
8dc7d8c136
1 changed files with 10 additions and 2 deletions
12
context.go
12
context.go
|
|
@ -1160,17 +1160,25 @@ func (c *Context) SetSameSite(samesite http.SameSite) {
|
|||
}
|
||||
|
||||
// SetCookie 设置一个 HTTP cookie
|
||||
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool) {
|
||||
// sameSite 参数是可选的,如果不提供则使用通过 SetSameSite 设置的值
|
||||
func (c *Context) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool, sameSite ...http.SameSite) {
|
||||
if path == "" {
|
||||
path = "/"
|
||||
}
|
||||
site := c.sameSite
|
||||
if len(sameSite) > 0 {
|
||||
if len(sameSite) > 1 {
|
||||
c.Warnf("SetCookie: only the first SameSite value will be used, got %d values", len(sameSite))
|
||||
}
|
||||
site = sameSite[0]
|
||||
}
|
||||
http.SetCookie(c.Writer, &http.Cookie{
|
||||
Name: name,
|
||||
Value: url.QueryEscape(value),
|
||||
MaxAge: maxAge,
|
||||
Path: path,
|
||||
Domain: domain,
|
||||
SameSite: c.sameSite,
|
||||
SameSite: site,
|
||||
Secure: secure,
|
||||
HttpOnly: httpOnly,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue