You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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(outinterface{}) error
413
+
```
414
+
415
+
```go title="Example"
416
+
// Field names should start with an uppercase letter
| 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}`|
| 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}`|
Copy file name to clipboardExpand all lines: versioned_docs/version-v2.x/api/middleware/compress.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,10 @@ id: compress
6
6
7
7
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.
8
8
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)
0 commit comments