Skip to content

Commit

Permalink
Add docs from gofiber/fiber@56d60a0
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jun 30, 2024
1 parent b199a6a commit 79d04c0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
41 changes: 31 additions & 10 deletions docs/core/api/ctx.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,17 @@ func (c Ctx) Cookie(cookie *Cookie)

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

Expand All @@ -402,6 +403,26 @@ app.Get("/", func(c fiber.Ctx) error {
})
```

:::info

Partitioned cookies allow partitioning 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.

:::

```go title="Example"
app.Get("/", func(c fiber.Ctx) error {
// Create a new partitioned cookie
cookie := new(fiber.Cookie)
cookie.Name = "user_session"
cookie.Value = "abc123"
cookie.Partitioned = true // This cookie will be stored in a separate jar when it's embeded into another website

// Set the cookie in the response
c.Cookie(cookie)
return c.SendString("Partitioned cookie set")
})
```

## Cookies

Get cookie value by key, you could pass an optional default value that will be returned if the cookie key does not exist.
Expand Down
3 changes: 3 additions & 0 deletions docs/core/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ To enable the routing changes above we had to slightly adjust the signature of t
DRAFT section
:::

### New Features

- Cookie now allows Partitioned cookies for [CHIPS](https://developers.google.com/privacy-sandbox/3pcd/chips) support. CHIPS (Cookies Having Independent Partitioned State) is a feature that improves privacy by allowing cookies to be partitioned by top-level site, mitigating cross-site tracking.

### new methods

Expand Down

0 comments on commit 79d04c0

Please sign in to comment.