Skip to content

Commit 2e42de7

Browse files
1 parent 79b6d99 commit 2e42de7

26 files changed

Lines changed: 377 additions & 178 deletions

versioned_docs/version-v3.x/addon/retry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ type Config struct {
107107
//
108108
// Optional. Default: 10
109109
MaxRetryCount int
110+
111+
// currentInterval tracks the current waiting time.
112+
//
113+
// Optional. Default: 1 * time.Second
114+
currentInterval time.Duration
110115
}
111116
```
112117

versioned_docs/version-v3.x/api/app.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ type Register interface {
157157
Options(handler any, handlers ...any) Register
158158
Trace(handler any, handlers ...any) Register
159159
Patch(handler any, handlers ...any) Register
160+
Query(handler any, handlers ...any) Register
160161

161162
Add(methods []string, handler any, handlers ...any) Register
162163

versioned_docs/version-v3.x/api/constants.md

Lines changed: 92 additions & 86 deletions
Large diffs are not rendered by default.

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,11 @@ By default, `c.IP()` returns the remote IP address from the TCP connection. When
11501150

11511151
**Important:** You must enable `TrustProxy` and configure trusted proxy IPs to prevent header spoofing. Simply setting `ProxyHeader` alone will not work.
11521152

1153-
**Note:** When using a proxy header such as `X-Forwarded-For`, `c.IP()` returns the raw header value unless [`EnableIPValidation`](fiber.md#enableipvalidation) is enabled. For `X-Forwarded-For`, this raw value may be a comma-separated list of IPs; enable `EnableIPValidation` if you need `c.IP()` to return a single, validated client IP.
1153+
**Note:** When using a proxy header such as `X-Forwarded-For`, `c.IP()` returns the raw header value unless [`EnableIPValidation`](fiber.md#enableipvalidation) is enabled.
1154+
1155+
**Chain parsing with `EnableIPValidation`:** For `X-Forwarded-For`, the raw value is a comma-separated chain that grows from left to right as the request passes through each proxy. With validation enabled, `c.IP()` walks the chain from right to left, skipping every IP that matches the configured `TrustProxyConfig` (exact IPs, CIDR ranges, loopback, private or link-local) and returns the first non-trusted IP it finds. This matches the behavior recommended by [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For#selecting_an_ip_address) and the convention used by Nginx (`set_real_ip_from` + `real_ip_recursive`), Apache `mod_remoteip`, and Envoy (`xff_num_trusted_hops`).
1156+
1157+
If every IP in the chain matches the trusted set, the leftmost IP is returned as a fallback. If the chain is empty, `c.IP()` falls back to the TCP remote address.
11541158
:::
11551159

11561160
#### Configuration for apps behind a reverse proxy
@@ -1564,7 +1568,11 @@ app.Get("/", func(c fiber.Ctx) error {
15641568

15651569
### Protocol
15661570

1567-
Contains the request protocol string: `http` or `https` for **TLS** requests.
1571+
Returns the HTTP protocol version of the request: `HTTP/1.1` or `HTTP/2`.
1572+
1573+
:::info
1574+
To get the request scheme (`http` or `https`), use [`Scheme`](#scheme) instead.
1575+
:::
15681576

15691577
```go title="Signature"
15701578
func (c fiber.Ctx) Protocol() string
@@ -1574,7 +1582,7 @@ func (c fiber.Ctx) Protocol() string
15741582
// GET http://example.com
15751583

15761584
app.Get("/", func(c fiber.Ctx) error {
1577-
c.Protocol() // "http"
1585+
c.Protocol() // "HTTP/1.1"
15781586

15791587
// ...
15801588
})
@@ -1828,7 +1836,7 @@ app.Post("/", func(c fiber.Ctx) error {
18281836
})
18291837
```
18301838

1831-
### Schema
1839+
### Scheme
18321840

18331841
Contains the request protocol string: `http` or `https` for TLS requests.
18341842

@@ -1837,14 +1845,14 @@ Please use [`Config.TrustProxy`](fiber.md#trustproxy) to prevent header spoofing
18371845
:::
18381846

18391847
```go title="Signature"
1840-
func (c fiber.Ctx) Schema() string
1848+
func (c fiber.Ctx) Scheme() string
18411849
```
18421850

18431851
```go title="Example"
18441852
// GET http://example.com
18451853

18461854
app.Get("/", func(c fiber.Ctx) error {
1847-
c.Schema() // "http"
1855+
c.Scheme() // "http"
18481856

18491857
// ...
18501858
})
@@ -1860,7 +1868,7 @@ func (c fiber.Ctx) Secure() bool
18601868

18611869
```go title="Example"
18621870
// Secure() method is equivalent to:
1863-
c.Protocol() == "https"
1871+
c.Scheme() == "https"
18641872
```
18651873

18661874
### Stale

versioned_docs/version-v3.x/api/fiber.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ app.Listen(":8080", fiber.ListenConfig{
120120
| <Reference id="ShutdownTimeout">ShutdownTimeout</Reference> | `time.Duration` | Specifies the maximum duration to wait for the server to gracefully shutdown. When the timeout is reached, the graceful shutdown process is interrupted and forcibly terminated, and the `context.DeadlineExceeded` error is passed to the `OnPostShutdown` callback. Set to 0 to disable the timeout and wait indefinitely. | `10 * time.Second` |
121121
| <Reference id="listeneraddrfunc">ListenerAddrFunc</Reference> | `func(addr net.Addr)` | Allows accessing and customizing `net.Listener`. | `nil` |
122122
| <Reference id="listenernetwork">ListenerNetwork</Reference> | `string` | Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "unix" (Unix Domain Sockets). WARNING: When prefork is set to true, only "tcp4" and "tcp6" can be chosen. | `tcp4` |
123+
| <Reference id="preforkrecoverinterval">PreforkRecoverInterval</Reference> | `time.Duration` | Delays the respawn of a crashed child process by this duration. Only applies when prefork is enabled. | `0` (respawn immediately) |
123124
| <Reference id="preforkrecoverthreshold">PreforkRecoverThreshold</Reference> | `int` | Defines the maximum number of child process restarts after crashes before the prefork master exits with an error. Only applies when prefork is enabled. | `max(1, runtime.GOMAXPROCS(0) / 2)` |
125+
| <Reference id="preforkshutdowngraceperiod">PreforkShutdownGracePeriod</Reference> | `time.Duration` | How long the prefork master waits for child processes to exit after SIGTERM before sending SIGKILL during shutdown. On Windows children are always killed immediately. Only applies when prefork is enabled. | `5 * time.Second` |
124126
| <Reference id="preforklogger">PreforkLogger</Reference> | `PreforkLogger` | Sets a custom logger for the prefork process manager. Only applies when prefork is enabled. | Fiber logger |
125127
| <Reference id="unixsocketfilemode">UnixSocketFileMode</Reference> | `os.FileMode` | FileMode to set for Unix Domain Socket (ListenerNetwork must be "unix") | `0770` |
126128
| <Reference id="tlsconfigfunc">TLSConfigFunc</Reference> | `func(tlsConfig *tls.Config)` | Allows customizing `tls.Config` as you want. Ignored when `TLSConfig` is set. | `nil` |

versioned_docs/version-v3.x/api/redirect.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Similar to [Laravel](https://laravel.com/docs/11.x/redirects#redirecting-with-fl
164164
Retrieve all flash messages. See [With](#with) for details.
165165

166166
```go title="Signature"
167-
func (r *Redirect) Messages() map[string]string
167+
func (r *Redirect) Messages() []FlashMessage
168168
```
169169

170170
```go title="Example"
@@ -179,13 +179,13 @@ app.Get("/", func(c fiber.Ctx) error {
179179
Get a flash message by key; see [With](#with).
180180

181181
```go title="Signature"
182-
func (r *Redirect) Message(key string) *Redirect
182+
func (r *Redirect) Message(key string) FlashMessage
183183
```
184184

185185
```go title="Example"
186186
app.Get("/", func(c fiber.Ctx) error {
187187
message := c.Redirect().Message("status")
188-
return c.SendString(message)
188+
return c.SendString(message.Value)
189189
})
190190
```
191191

@@ -194,7 +194,7 @@ app.Get("/", func(c fiber.Ctx) error {
194194
Retrieve stored input data. See [WithInput](#withinput).
195195

196196
```go title="Signature"
197-
func (r *Redirect) OldInputs() map[string]string
197+
func (r *Redirect) OldInputs() []OldInputData
198198
```
199199

200200
```go title="Example"
@@ -209,13 +209,13 @@ app.Get("/", func(c fiber.Ctx) error {
209209
Get stored input data by key; see [WithInput](#withinput).
210210

211211
```go title="Signature"
212-
func (r *Redirect) OldInput(key string) string
212+
func (r *Redirect) OldInput(key string) OldInputData
213213
```
214214

215215
```go title="Example"
216216
app.Get("/name", func(c fiber.Ctx) error {
217217
oldInput := c.Redirect().OldInput("name")
218-
return c.SendString(oldInput)
218+
return c.SendString(oldInput.Value)
219219
})
220220
```
221221

versioned_docs/version-v3.x/client/request.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,32 @@ This structure is designed to be both flexible and efficient, allowing you to ea
1818

1919
```go
2020
type Request struct {
21-
url string
22-
method string
23-
userAgent string
24-
boundary string
25-
referer string
26-
ctx context.Context
27-
header *Header
28-
params *QueryParam
29-
cookies *Cookie
30-
path *PathParam
21+
ctx context.Context
3122

32-
timeout time.Duration
33-
maxRedirects int
23+
body any
24+
header Header
25+
params QueryParam
26+
cookies Cookie
27+
path PathParam
3428

3529
client *Client
3630

37-
body any
38-
formData *FormData
39-
files []*File
40-
bodyType bodyType
31+
formData FormData
4132

4233
RawRequest *fasthttp.Request
34+
url string
35+
method string
36+
userAgent string
37+
boundary string
38+
referer string
39+
files []*File
40+
41+
timeout time.Duration
42+
maxRedirects int
43+
44+
bodyType bodyType
45+
46+
isPathNormalizingDisabled bool
4347
}
4448
```
4549

@@ -101,6 +105,14 @@ func (r *Request) Head(url string) (*Response, error)
101105
func (r *Request) Options(url string) (*Response, error)
102106
```
103107

108+
### Query
109+
110+
**Query** sends a QUERY request. It sets the URL and method to QUERY, then sends the request.
111+
112+
```go title="Signature"
113+
func (r *Request) Query(url string) (*Response, error)
114+
```
115+
104116
### Custom
105117

106118
**Custom** sends a request using a custom HTTP method. For example, you can use this to send a TRACE or CONNECT request.

versioned_docs/version-v3.x/client/rest.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,13 @@ See [examples](examples.md) for more detailed usage.
4949

5050
```go
5151
type Client struct {
52-
mu sync.RWMutex
52+
logger log.CommonLogger
53+
transport httpClientTransport
5354

54-
fasthttp *fasthttp.Client
55-
56-
baseURL string
57-
userAgent string
58-
referer string
59-
header *Header
60-
params *QueryParam
61-
cookies *Cookie
62-
path *PathParam
63-
64-
debug bool
65-
66-
timeout time.Duration
67-
68-
// user-defined request hooks
69-
userRequestHooks []RequestHook
70-
71-
// client package-defined request hooks
72-
builtinRequestHooks []RequestHook
73-
74-
// user-defined response hooks
75-
userResponseHooks []ResponseHook
76-
77-
// client package-defined response hooks
78-
builtinResponseHooks []ResponseHook
55+
header *Header
56+
params *QueryParam
57+
cookies *Cookie
58+
path *PathParam
7959

8060
jsonMarshal utils.JSONMarshal
8161
jsonUnmarshal utils.JSONUnmarshal
@@ -84,16 +64,20 @@ type Client struct {
8464
cborMarshal utils.CBORMarshal
8565
cborUnmarshal utils.CBORUnmarshal
8666

87-
cookieJar *CookieJar
88-
89-
// proxy
90-
proxyURL string
91-
92-
// retry
93-
retryConfig *RetryConfig
67+
cookieJar *CookieJar
68+
retryConfig *RetryConfig
69+
baseURL string
70+
userAgent string
71+
referer string
72+
userRequestHooks []RequestHook
73+
builtinRequestHooks []RequestHook
74+
userResponseHooks []ResponseHook
75+
builtinResponseHooks []ResponseHook
9476

95-
// logger
96-
logger log.CommonLogger
77+
timeout time.Duration
78+
mu sync.RWMutex
79+
isDebug bool
80+
isPathNormalizingDisabled bool
9781
}
9882
```
9983

@@ -149,6 +133,14 @@ Sends a PATCH request.
149133
func (c *Client) Patch(url string, cfg ...Config) (*Response, error)
150134
```
151135

136+
### Query
137+
138+
Sends a QUERY request.
139+
140+
```go title="Signature"
141+
func (c *Client) Query(url string, cfg ...Config) (*Response, error)
142+
```
143+
152144
### Delete
153145

154146
Sends a DELETE request.
@@ -893,6 +885,14 @@ Patch is a convenience method that sends a PATCH request using the `defaultClien
893885
func Patch(url string, cfg ...Config) (*Response, error)
894886
```
895887

888+
### Query
889+
890+
Query is a convenience method that sends a QUERY request using the `defaultClient`.
891+
892+
```go title="Signature"
893+
func Query(url string, cfg ...Config) (*Response, error)
894+
```
895+
896896
### Delete
897897

898898
Delete is a convenience method that sends a DELETE request using the `defaultClient`.
@@ -922,7 +922,7 @@ func Options(url string, cfg ...Config) (*Response, error)
922922
**Replace** replaces the default client with a new one. It returns a function that can restore the old client.
923923

924924
:::caution
925-
Do not modify the default client concurrently.
925+
Replacing the default client is concurrency-safe, but mutating the same `Client` instance still requires external synchronization.
926926
:::
927927

928928
```go title="Signature"

versioned_docs/version-v3.x/extra/faq.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,24 @@ For details on how to:
198198
* Convert `fiber.Ctx` to `http.Request`
199199

200200
See the dedicated documentation: [Adaptor Documentation](../middleware/adaptor.md).
201+
202+
## Troubleshooting common errors
203+
204+
Crashes that surface in unrelated packages, with stack traces that never mention Fiber, usually trace back to a context value kept past the handler. The cases below name the symptom so a search for the panic text lands here.
205+
206+
### Panic `id (N) <= evictCount (M)` (hpack / HTTP/2 / gRPC) {#panic-id-evictcount-hpack-grpc}
207+
208+
This is not a bug in Fiber, gRPC, or `golang.org/x/net/http2`. It means a Fiber zero-copy context value (a header from `c.Get`, or `c.Query`, `c.Params`, `c.Cookies`, `c.Body`) was kept past the handler. Fiber reuses the request buffer on the next request, so the retained bytes change underneath whatever stored them. See [Zero Allocation](../intro.md#zero-allocation) for the underlying behavior.
209+
210+
A common trigger is forwarding a header into a long-lived gRPC / HTTP/2 client's `metadata`. The value is held in the connection's HPACK dynamic table and later mutates, crashing the process inside the HPACK encoder, in a stack trace that never mentions Fiber:
211+
212+
```text
213+
panic: id (N) <= evictCount (M)
214+
golang.org/x/net/http2/hpack.(*headerFieldTable).idToIndex
215+
...
216+
google.golang.org/grpc/internal/transport.(*loopyWriter).writeHeader
217+
```
218+
219+
The crash is decoupled from your handler in both time and call stack, so ordinary tests and even the `-race` detector usually miss it.
220+
221+
The fix is to detach the value before you keep it: copy it with `utils.CopyString` (or `strings.Clone`), or enable [`Immutable`](../api/fiber.md#immutable). A full reproduction is in [gofiber/fiber#4464](https://github.com/gofiber/fiber/issues/4464).

versioned_docs/version-v3.x/extra/internal.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ Fiber provides a comprehensive hook system that allows you to run custom functio
401401
- OnName: Invoked when a route is assigned a name.
402402
- OnGroup: Triggered when a group is created.
403403
- OnListen: Runs when the server starts listening.
404-
- OnShutdown: Called during graceful shutdown.
404+
- OnPreShutdown: Runs before the application shuts down.
405+
- OnPostShutdown: Runs after shutdown and receives the shutdown result.
405406
- OnFork: Invoked when a child process is forked.
406407
- OnMount: Used when a sub‑application is mounted.
407408

@@ -412,15 +413,17 @@ flowchart TD
412413
ON[OnName]
413414
OG[OnGroup]
414415
OL[OnListen]
415-
OS[OnShutdown]
416+
OPRS[OnPreShutdown]
417+
OPOS[OnPostShutdown]
416418
OF[OnFork]
417419
OM[OnMount]
418420
419421
H --> OR
420422
H --> ON
421423
H --> OG
422424
H --> OL
423-
H --> OS
425+
H --> OPRS
426+
H --> OPOS
424427
H --> OF
425428
H --> OM
426429
```

0 commit comments

Comments
 (0)