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
Copy file name to clipboardExpand all lines: docs/core/api/fiber.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,7 @@ app := fiber.New(fiber.Config{
55
55
| <Referenceid="disableheadernormalizing">DisableHeaderNormalizing</Reference> |`bool`| By default all header names are normalized: conteNT-tYPE -> Content-Type |`false`|
56
56
| <Referenceid="disablekeepalive">DisableKeepalive</Reference> |`bool`| Disables keep-alive connections so the server closes each connection after the first response. |`false`|
57
57
| <Referenceid="disablepreparsemultipartform">DisablePreParseMultipartForm</Reference> |`bool`| Will not pre parse Multipart Form data if set to true. This option is useful for servers that desire to treat multipart form data as a binary blob, or choose when to parse the data. |`false`|
58
+
| <Referenceid="disableheadautoregister">DisableHeadAutoRegister</Reference> |`bool`| Prevents Fiber from automatically registering `HEAD` routes for each `GET` route so you can supply custom `HEAD` handlers; manual `HEAD` routes still override the generated ones. |`false`|
58
59
| <Referenceid="enableipvalidation">EnableIPValidation</Reference> |`bool`| If set to true, `c.IP()` and `c.IPs()` will validate IP addresses before returning them. Also, `c.IP()` will return only the first valid IP rather than just the raw header value that may be a comma separated string.<br /><br />**WARNING:** There is a small performance cost to doing this validation. Keep disabled if speed is your only concern and your application is behind a trusted proxy that already validates this header. |`false`|
59
60
| <Referenceid="enablesplittingonparsers">EnableSplittingOnParsers</Reference> |`bool`| Splits query, body, and header parameters on commas when enabled.<br /><br />For example, `/api?foo=bar,baz` becomes `foo[]=bar&foo[]=baz`. |`false`|
60
61
| <Referenceid="trustproxy">TrustProxy</Reference> |`bool`| When true, Fiber validates the proxy IP against `TrustProxyConfig.Proxies`. <br /><br />By default, `c.Protocol()`, `c.IP()`, and `c.Hostname()` read values from standard X-Forwarded headers. If the remote IP matches a trusted proxy, these methods behave as if `TrustProxy` were disabled. Otherwise, `c.Protocol()` reflects the connection scheme, `c.IP()` uses `RemoteIP()` from Fasthttp, and `c.Hostname()` uses `fasthttp.Request.URI().Host()`|`false`|
Copy file name to clipboardExpand all lines: docs/core/guide/routing.md
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,43 @@ import RoutingHandler from './../partials/routing/handler.md';
16
16
17
17
<RoutingHandler />
18
18
19
+
## Automatic HEAD routes
20
+
21
+
Fiber automatically registers a `HEAD` route for every `GET` route you add. The generated handler chain mirrors the `GET` chain, so `HEAD` requests reuse middleware, status codes, and headers while the response body is suppressed.
// HEAD /users/:id now returns the same headers and status without a body.
32
+
```
33
+
34
+
You can still register dedicated `HEAD` handlers—even with auto-registration enabled—and Fiber replaces the generated route so your implementation wins:
35
+
36
+
```go title="Override the generated HEAD handler"
37
+
app.Head("/users/:id", func(c fiber.Ctx) error {
38
+
return c.SendStatus(fiber.StatusNoContent)
39
+
})
40
+
```
41
+
42
+
To opt out globally, start the app with `DisableHeadAutoRegister`:
app.Get("/users/:id", handler) // HEAD /users/:id now returns 405 unless you add it manually.
52
+
```
53
+
54
+
Auto-generated `HEAD` routes participate in every router scope, including `Group` hierarchies, mounted sub-apps, parameterized and wildcard paths, and static file helpers. They also appear in route listings such as `app.Stack()` so tooling sees both the `GET` and `HEAD` entries.
55
+
19
56
## Paths
20
57
21
58
A route path paired with an HTTP method defines an endpoint. It can be a plain **string** or a **pattern**.
You can find more information about `app.RouteChain` and `app.Route` in the API documentation ([RouteChain](./api/app#routechain), [Route](./api/app#route)).
358
358
359
+
### Automatic HEAD routes for GET
360
+
361
+
Fiber now auto-registers a `HEAD` route whenever you add a `GET` route. The generated handler chain matches the `GET` chain so status codes and headers stay in sync while the response body remains empty, ensuring `HEAD` clients observe the same metadata as a `GET` consumer.
362
+
363
+
```go title="GET now enables HEAD automatically"
364
+
app:= fiber.New()
365
+
366
+
app.Get("/health", func(c fiber.Ctx) error {
367
+
c.Set("X-Service", "api")
368
+
return c.SendString("OK")
369
+
})
370
+
371
+
// HEAD /health reuses the GET middleware chain and returns headers only.
372
+
```
373
+
374
+
You can still register explicit `HEAD` handlers for any `GET` route, and they continue to win when you add them:
375
+
376
+
```go title="Override the generated HEAD handler"
377
+
app.Head("/health", func(c fiber.Ctx) error {
378
+
return c.SendStatus(fiber.StatusNoContent)
379
+
})
380
+
```
381
+
382
+
Prefer to manage `HEAD` routes yourself? Disable the feature through `fiber.Config.DisableHeadAutoRegister`:
app.Get("/health", handler) // HEAD /health now returns 405 unless you add it manually.
392
+
```
393
+
394
+
Auto-generated `HEAD` routes appear in tooling such as `app.Stack()` and cover the same routing scenarios as their `GET` counterparts, including groups, mounted apps, dynamic parameters, and static file handlers.
395
+
359
396
### Middleware registration
360
397
361
398
We have aligned our method for middlewares closer to [`Express`](https://expressjs.com/en/api.html#app.use) and now also support the [`Use`](./api/app#use) of multiple prefixes.
0 commit comments