gpt4 book ai didi

http - Golang Cookie Max-Age 与过期

转载 作者:行者123 更新时间:2023-12-05 00:43:13 29 4
gpt4 key购买 nike

Cookie struct 中的 Expires 和 Max-Age 有什么区别?看不懂。

type Cookie struct {
Name string
Value string

Path string // optional
Domain string // optional
Expires time.Time // optional
RawExpires string // for reading cookies only

// MaxAge=0 means no 'Max-Age' attribute specified.
// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'
// MaxAge>0 means Max-Age attribute present and given in seconds
MaxAge int
Secure bool
HttpOnly bool
SameSite SameSite
Raw string
Unparsed []string // Raw text of unparsed attribute-value pairs
}

最佳答案

它们实际上是 Set-Cookie header 的不同字段,并不特定于 Go。

来自 Mozilla docs :

过期

Indicates the maximum lifetime of the cookie as an HTTP-date timestamp. See Date for the required formatting.

If unspecified, the cookie becomes a session cookie. A session finishes when the client shuts down, after which the session cookie is removed.

Warning: Many web browsers have a session restore feature that will save all tabs and restore them the next time the browser is used. Session cookies will also be restored, as if the browser was never closed.

When an Expires date is set, the deadline is relative to the client the cookie is being set on, not the server.

最大年龄

Indicates the number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.

关于http - Golang Cookie Max-Age 与过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70715904/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com