Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConfigDefault = Config{ Next: nil, Timeout: 0, OnTimeout: nil, Errors: nil, }
ConfigDefault is the default configuration.
Functions ¶
func New ¶
New enforces a timeout for each incoming request. It replaces the request's context with one that has the configured deadline, which is exposed through c.Context(). Handlers can detect the timeout by listening on c.Context().Done() and return early.
When a timeout occurs, the middleware returns immediately with fiber.ErrServiceUnavailable (or the result of OnTimeout if configured). The status is 503, not 408: a slow handler is a server-side delay, and 408 (RFC 9110 §15.5.9) invites the client to resend a request whose handler may still be running. The handler goroutine can continue safely, and resources are recycled when it finishes via the Abandon/ForceRelease mechanism.
Types ¶
type Config ¶
type Config struct {
// Next defines a function to skip this middleware.
// Optional. Default: nil
Next func(c fiber.Ctx) bool
// OnTimeout is executed when a timeout occurs. It may write the response or
// return a *fiber.Error that shapes it; otherwise the default 503 is sent.
// The timed-out handler may still be running and must stop using the context.
// Optional. Default: nil (return fiber.ErrServiceUnavailable)
OnTimeout fiber.Handler
// Errors defines custom errors that are treated as timeouts.
// Optional. Default: nil
Errors []error
// Timeout defines the timeout duration for all routes.
// Optional. Default: 0 (no timeout)
Timeout time.Duration
}
Config holds the configuration for the timeout middleware.