diff options
author | Gürkan Yeşilyurt <gurkanyesilyurt07@gmail.com> | 2024-04-08 19:23:23 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-08 18:23:23 +0200 |
commit | a77e9c6b7907610f423cb3ac1cf447a5b292c6fa (patch) | |
tree | aed2cad166e397f11b83db4fc17880909c9c4608 /cookie.go | |
parent | chore(deps): bump golang.org/x/net from 0.22.0 to 0.23.0 (#1748) (diff) | |
download | fasthttp-a77e9c6b7907610f423cb3ac1cf447a5b292c6fa.tar.gz fasthttp-a77e9c6b7907610f423cb3ac1cf447a5b292c6fa.tar.bz2 fasthttp-a77e9c6b7907610f423cb3ac1cf447a5b292c6fa.zip |
add support for CHIPS (Cookies Having Independent Partitioned State) (#1752)
* add support for CHIPS (Cookies Having Independent Partitioned State)
* fix comment lines
* Update cookie.go fix lint error: should omit comparison to bool constant
Diffstat (limited to 'cookie.go')
-rw-r--r-- | cookie.go | 34 |
1 files changed, 30 insertions, 4 deletions
@@ -33,7 +33,7 @@ const ( CookieSameSiteStrictMode // CookieSameSiteNoneMode sets the SameSite flag with the "None" parameter. // See https://tools.ietf.org/html/draft-west-cookie-incrementalism-00 - CookieSameSiteNoneMode + CookieSameSiteNoneMode // third-party cookies are phasing out, use Partitioned cookies instead ) // AcquireCookie returns an empty Cookie object from the pool. @@ -74,9 +74,10 @@ type Cookie struct { domain []byte path []byte - httpOnly bool - secure bool - sameSite CookieSameSite + httpOnly bool + secure bool + sameSite CookieSameSite + partitioned bool bufKV argsKV buf []byte @@ -94,6 +95,7 @@ func (c *Cookie) CopyTo(src *Cookie) { c.httpOnly = src.httpOnly c.secure = src.secure c.sameSite = src.sameSite + c.partitioned = src.partitioned } // HTTPOnly returns true if the cookie is http only. @@ -130,6 +132,21 @@ func (c *Cookie) SetSameSite(mode CookieSameSite) { } } +// Partitioned returns true if the cookie is partitioned. +func (c *Cookie) Partitioned() bool { + return c.partitioned +} + +// SetPartitioned sets the cookie's Partitioned flag to the given value. +// Set value Partitioned to true will set Secure to true and Path to / also to avoid browser rejection. +func (c *Cookie) SetPartitioned(partitioned bool) { + c.partitioned = partitioned + if partitioned { + c.SetSecure(true) + c.SetPath("/") + } +} + // Path returns cookie path. func (c *Cookie) Path() []byte { return c.path @@ -247,6 +264,7 @@ func (c *Cookie) Reset() { c.httpOnly = false c.secure = false c.sameSite = CookieSameSiteDisabled + c.partitioned = false } // AppendBytes appends cookie representation to dst and returns @@ -304,6 +322,10 @@ func (c *Cookie) AppendBytes(dst []byte) []byte { dst = append(dst, '=') dst = append(dst, strCookieSameSiteNone...) } + if c.partitioned { + dst = append(dst, ';', ' ') + dst = append(dst, strCookiePartitioned...) + } return dst } @@ -425,6 +447,10 @@ func (c *Cookie) ParseBytes(src []byte) error { } else if caseInsensitiveCompare(strCookieSameSite, kv.value) { c.sameSite = CookieSameSiteDefaultMode } + case 'p': // "partitioned" + if caseInsensitiveCompare(strCookiePartitioned, kv.value) { + c.partitioned = true + } } } // else empty or no match } |