mirror of
https://github.com/infinite-iroha/touka.git
synced 2026-06-13 15:47:38 +08:00
feat(cookie): add SameSite support to SetCookie method
This commit is contained in:
parent
3aa84f5dcf
commit
7be49b96c8
1 changed files with 7 additions and 2 deletions
|
|
@ -1160,17 +1160,22 @@ 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 {
|
||||
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