Skip to content

Commit dc50d04

Browse files
committed
update docs
1 parent 65466c6 commit dc50d04

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

ctx.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,17 @@ type RangeSet struct {
9696

9797
// Cookie data for c.Cookie
9898
type Cookie struct {
99-
Name string `json:"name"`
100-
Value string `json:"value"`
101-
Path string `json:"path"`
102-
Domain string `json:"domain"`
103-
MaxAge int `json:"max_age"`
104-
Expires time.Time `json:"expires"`
105-
Secure bool `json:"secure"`
106-
HTTPOnly bool `json:"http_only"`
107-
SameSite string `json:"same_site"`
108-
Partitioned bool `json:"partitioned"`
109-
SessionOnly bool `json:"session_only"`
99+
Name string `json:"name"` // The name of the cookie
100+
Value string `json:"value"` // The value of the cookie
101+
Path string `json:"path"` // Specifies a URL path which is allowed to receive the cookie
102+
Domain string `json:"domain"` // Specifies the domain which is allowed to receive the cookie
103+
MaxAge int `json:"max_age"` // The maximum age (in seconds) of the cookie
104+
Expires time.Time `json:"expires"` // The expiration date of the cookie
105+
Secure bool `json:"secure"` // Indicates that the cookie should only be transmitted over a secure HTTPS connection
106+
HTTPOnly bool `json:"http_only"` // Indicates that the cookie is accessible only through the HTTP protocol
107+
SameSite string `json:"same_site"` // Controls whether or not a cookie is sent with cross-site requests
108+
Partitioned bool `json:"partitioned"` // Indicates if the cookie is stored in a partitioned cookie jar
109+
SessionOnly bool `json:"session_only"` // Indicates if the cookie is a session-only cookie
110110
}
111111

112112
// Views is the interface that wraps the Render function.

docs/api/ctx.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,26 +375,20 @@ func (c Ctx) Cookie(cookie *Cookie)
375375

376376
```go
377377
type Cookie struct {
378-
Name string `json:"name"`
379-
Value string `json:"value"`
380-
Path string `json:"path"`
381-
Domain string `json:"domain"`
382-
MaxAge int `json:"max_age"`
383-
Expires time.Time `json:"expires"`
384-
Secure bool `json:"secure"`
385-
HTTPOnly bool `json:"http_only"`
386-
SameSite string `json:"same_site"`
387-
Partitioned bool `json:"chips"`
388-
SessionOnly bool `json:"session_only"`
378+
Name string `json:"name"` // The name of the cookie
379+
Value string `json:"value"` // The value of the cookie
380+
Path string `json:"path"` // Specifies a URL path which is allowed to receive the cookie
381+
Domain string `json:"domain"` // Specifies the domain which is allowed to receive the cookie
382+
MaxAge int `json:"max_age"` // The maximum age (in seconds) of the cookie
383+
Expires time.Time `json:"expires"` // The expiration date of the cookie
384+
Secure bool `json:"secure"` // Indicates that the cookie should only be transmitted over a secure HTTPS connection
385+
HTTPOnly bool `json:"http_only"` // Indicates that the cookie is accessible only through the HTTP protocol
386+
SameSite string `json:"same_site"` // Controls whether or not a cookie is sent with cross-site requests
387+
Partitioned bool `json:"partitioned"` // Indicates if the cookie is stored in a partitioned cookie jar
388+
SessionOnly bool `json:"session_only"` // Indicates if the cookie is a session-only cookie
389389
}
390390
```
391391

392-
:::info
393-
394-
Partitioned cookies allow to partition cookie jar by top-level site. You can check out [CHIPS](https://developers.google.com/privacy-sandbox/3pcd/chips) for more information.
395-
396-
:::
397-
398392
```go title="Example"
399393
app.Get("/", func(c fiber.Ctx) error {
400394
// Create cookie
@@ -409,6 +403,26 @@ app.Get("/", func(c fiber.Ctx) error {
409403
})
410404
```
411405

406+
:::info
407+
408+
Partitioned cookies allow to partition the cookie jar by top-level site, enhancing user privacy by preventing cookies from being shared across different sites. This feature is particularly useful in scenarios where a user interacts with embedded third-party services that should not have access to the main site's cookies. You can check out [CHIPS](https://developers.google.com/privacy-sandbox/3pcd/chips) for more information.
409+
410+
:::
411+
412+
```go title="Example"
413+
app.Get("/", func(c fiber.Ctx) error {
414+
// Create a new partitioned cookie
415+
cookie := new(fiber.Cookie)
416+
cookie.Name = "user_session"
417+
cookie.Value = "abc123"
418+
cookie.Partitioned = true // This cookie will be stored in a separate jar when it's embeded into another website
419+
420+
// Set the cookie in the response
421+
c.Cookie(cookie)
422+
return c.SendString("Partitioned cookie set")
423+
})
424+
```
425+
412426
## Cookies
413427

414428
Get cookie value by key, you could pass an optional default value that will be returned if the cookie key does not exist.

0 commit comments

Comments
 (0)