Skip to content

Commit 03176dc

Browse files
1 parent 39aef82 commit 03176dc

File tree

9 files changed

+235
-41
lines changed

9 files changed

+235
-41
lines changed

versioned_docs/version-v2.x/api/ctx.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,38 @@ app.Get("/", func(c *fiber.Ctx) error {
403403
})
404404
```
405405

406+
## CookieParser
407+
408+
This method is similar to [BodyParser](ctx.md#bodyparser), but for cookie parameters.
409+
It is important to use the struct tag "cookie". For example, if you want to parse a cookie with a field called Age, you would use a struct field of `cookie:"age"`.
410+
411+
```go title="Signature"
412+
func (c *Ctx) CookieParser(out interface{}) error
413+
```
414+
415+
```go title="Example"
416+
// Field names should start with an uppercase letter
417+
type Person struct {
418+
Name string `cookie:"name"`
419+
Age int `cookie:"age"`
420+
Job bool `cookie:"job"`
421+
}
422+
423+
app.Get("/", func(c *fiber.Ctx) error {
424+
p := new(Person)
425+
426+
if err := c.CookieParser(p); err != nil {
427+
return err
428+
}
429+
430+
log.Println(p.Name) // Joseph
431+
log.Println(p.Age) // 23
432+
log.Println(p.Job) // true
433+
})
434+
// Run tests with the following curl command
435+
// curl.exe --cookie "name=Joseph; age=23; job=true" http://localhost:8000/
436+
```
437+
406438
## Cookies
407439

408440
Get cookie value by key, you could pass an optional default value that will be returned if the cookie key does not exist.
@@ -554,7 +586,7 @@ app.Get("/", func(c *fiber.Ctx) error {
554586
Returns the HTTP request headers.
555587

556588
```go title="Signature"
557-
func (c *Ctx) GetReqHeaders() map[string]string
589+
func (c *Ctx) GetReqHeaders() map[string][]string
558590
```
559591

560592
> _Returned value is only valid within the handler. Do not store any references.
@@ -589,7 +621,7 @@ app.Get("/", func(c *fiber.Ctx) error {
589621
Returns the HTTP response headers.
590622

591623
```go title="Signature"
592-
func (c *Ctx) GetRespHeaders() map[string]string
624+
func (c *Ctx) GetRespHeaders() map[string][]string
593625
```
594626

595627
> _Returned value is only valid within the handler. Do not store any references.
@@ -1710,6 +1742,10 @@ app.Get("/file-with-url-chars", func(c *fiber.Ctx) error {
17101742
})
17111743
```
17121744
1745+
:::info
1746+
For sending files from embedded file system [this functionality](./middleware/filesystem.md#sendfile) can be used
1747+
:::
1748+
17131749
## SendStatus
17141750
17151751
Sets the status code and the correct status message in the body, if the response body is **empty**.

versioned_docs/version-v2.x/api/middleware/cache.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ app.Use(cache.New())
3636
// Or extend your config for customization
3737
app.Use(cache.New(cache.Config{
3838
Next: func(c *fiber.Ctx) bool {
39-
return c.Query("refresh") == "true"
39+
return c.Query("noCache") == "true"
4040
},
4141
Expiration: 30 * time.Minute,
4242
CacheControl: true,
@@ -64,20 +64,20 @@ app.Get("/", func(c *fiber.Ctx) error {
6464

6565
## Config
6666

67-
| Property | Type | Description | Default |
68-
|:---------------------|:------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------|
69-
| Next | `func(*fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
70-
| Expiration | `time.Duration` | Expiration is the time that a cached response will live. | `1 * time.Minute` |
71-
| CacheHeader | `string` | CacheHeader is the header on the response header that indicates the cache status, with the possible return values "hit," "miss," or "unreachable." | `X-Cache` |
72-
| CacheControl | `bool` | CacheControl enables client-side caching if set to true. | `false` |
73-
| KeyGenerator | `func(*fiber.Ctx) string` | Key allows you to generate custom keys. | `func(c *fiber.Ctx) string { return utils.CopyString(c.Path()) }` |
74-
| ExpirationGenerator | `func(*fiber.Ctx, *cache.Config) time.Duration` | ExpirationGenerator allows you to generate custom expiration keys based on the request. | `nil` |
75-
| Storage | `fiber.Storage` | Store is used to store the state of the middleware. | In-memory store |
76-
| Store (Deprecated) | `fiber.Storage` | Deprecated: Use Storage instead. | In-memory store |
77-
| Key (Deprecated) | `func(*fiber.Ctx) string` | Deprecated: Use KeyGenerator instead. | `nil` |
78-
| StoreResponseHeaders | `bool` | StoreResponseHeaders allows you to store additional headers generated by next middlewares & handler. | `false` |
79-
| MaxBytes | `uint` | MaxBytes is the maximum number of bytes of response bodies simultaneously stored in cache. | `0` (No limit) |
80-
| Methods | `[]string` | Methods specifies the HTTP methods to cache. | `[]string{fiber.MethodGet, fiber.MethodHead}` |
67+
| Property | Type | Description | Default |
68+
|:---------------------|:------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------|
69+
| Next | `func(*fiber.Ctx) bool` | Next defines a function that is executed before creating the cache entry and can be used to execute the request without cache creation. If an entry already exists, it will be used. If you want to completely bypass the cache functionality in certain cases, you should use the [skip middleware](./skip.md). | `nil` |
70+
| Expiration | `time.Duration` | Expiration is the time that a cached response will live. | `1 * time.Minute` |
71+
| CacheHeader | `string` | CacheHeader is the header on the response header that indicates the cache status, with the possible return values "hit," "miss," or "unreachable." | `X-Cache` |
72+
| CacheControl | `bool` | CacheControl enables client-side caching if set to true. | `false` |
73+
| KeyGenerator | `func(*fiber.Ctx) string` | Key allows you to generate custom keys. | `func(c *fiber.Ctx) string { return utils.CopyString(c.Path()) }` |
74+
| ExpirationGenerator | `func(*fiber.Ctx, *cache.Config) time.Duration` | ExpirationGenerator allows you to generate custom expiration keys based on the request. | `nil` |
75+
| Storage | `fiber.Storage` | Store is used to store the state of the middleware. | In-memory store |
76+
| Store (Deprecated) | `fiber.Storage` | Deprecated: Use Storage instead. | In-memory store |
77+
| Key (Deprecated) | `func(*fiber.Ctx) string` | Deprecated: Use KeyGenerator instead. | `nil` |
78+
| StoreResponseHeaders | `bool` | StoreResponseHeaders allows you to store additional headers generated by next middlewares & handler. | `false` |
79+
| MaxBytes | `uint` | MaxBytes is the maximum number of bytes of response bodies simultaneously stored in cache. | `0` (No limit) |
80+
| Methods | `[]string` | Methods specifies the HTTP methods to cache. | `[]string{fiber.MethodGet, fiber.MethodHead}` |
8181

8282
## Default Config
8383

versioned_docs/version-v2.x/api/middleware/compress.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ id: compress
66

77
Compression middleware for [Fiber](https://github.com/gofiber/fiber) that will compress the response using `gzip`, `deflate` and `brotli` compression depending on the [Accept-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding) header.
88

9+
:::note
10+
The compression middleware refrains from compressing bodies that are smaller than 200 bytes. This decision is based on the observation that, in such cases, the compressed size is likely to exceed the original size, making compression inefficient. [more](https://github.com/valyala/fasthttp/blob/497922a21ef4b314f393887e9c6147b8c3e3eda4/http.go#L1713-L1715)
11+
:::
12+
913
## Signatures
1014

1115
```go

0 commit comments

Comments
 (0)