Documentation
¶
Overview ¶
Package middleware supplies composable native HTTP middleware.
Index ¶
- func Chain(h http.Handler, m ...Middleware) http.Handler
- func ClientIP(r *http.Request, trusted []*net.IPNet) net.IP
- func Compression(next http.Handler) http.Handler
- func RequestID(next http.Handler) http.Handler
- func SecurityHeaders(next http.Handler) http.Handler
- type CORSConfig
- type Middleware
- func Authenticate(check func(*http.Request) (context.Context, error)) Middleware
- func Authorize(check func(*http.Request) error) Middleware
- func BodyLimit(n int64) Middleware
- func CORS(c CORSConfig) (Middleware, error)
- func ContentType(want string) Middleware
- func CorrelationID(trustForwarded bool) Middleware
- func Logging(l *slog.Logger) Middleware
- func Recovery(report func(context.Context, error)) Middleware
- func Timeout(d time.Duration) Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶
func Chain(h http.Handler, m ...Middleware) http.Handler
Chain applies middleware in left-to-right request order.
func ClientIP ¶
ClientIP trusts X-Forwarded-For only for explicitly trusted proxy CIDRs, peeling from the right.
func Compression ¶
Compression enables gzip when accepted, excluding protocol upgrades and bodyless responses.
Types ¶
type CORSConfig ¶
CORSConfig contains explicitly allowed origins, methods, headers and credential policy.
type Middleware ¶
Middleware returns context-aware HTTP admission or coordination middleware.
func Authenticate ¶
Authenticate attaches a verified identity context before authorization. Failure responses never expose verifier diagnostics.
func Authorize ¶
func Authorize(check func(*http.Request) error) Middleware
Authorize applies an explicit caller-supplied authorization policy.
func BodyLimit ¶
func BodyLimit(n int64) Middleware
BodyLimit limits request-body reading and rejects oversized declared bodies.
func CORS ¶
func CORS(c CORSConfig) (Middleware, error)
CORS validates CORS policy and returns its native middleware.
func ContentType ¶
func ContentType(want string) Middleware
ContentType enforces a parsed request MIME type when a body is present.
func CorrelationID ¶
func CorrelationID(trustForwarded bool) Middleware
CorrelationID generates a server-owned correlation ID unless a bounded forwarded ID is explicitly trusted.
func Logging ¶
func Logging(l *slog.Logger) Middleware
Logging returns structured request-logging instrumentation.
func Recovery ¶
func Recovery(report func(context.Context, error)) Middleware
Recovery returns a reporting panic-recovery interceptor or middleware.
func Timeout ¶
func Timeout(d time.Duration) Middleware
Timeout uses the standard buffered HTTP timeout handler; it is unsuitable for streaming.