Documentation
¶
Index ¶
- Constants
- func Apply(handler http.Handler, middlewares ...Middleware) http.Handler
- func MethodOverride(next http.HandlerFunc) http.HandlerFunc
- func NoContent(next http.HandlerFunc) http.HandlerFunc
- func RemoveTrailingSlash(next http.HandlerFunc) http.HandlerFunc
- type ConsumeFunc
- type ETagConfig
- type ErrorHandler
- type IPWhitelistConfig
- type Middleware
- func CSRF(errorHandler ErrorHandler) Middleware
- func ETag(config *ETagConfig) Middleware
- func IPWhitelist(config *IPWhitelistConfig) Middleware
- func MaxBytes(maxBytes func(*http.Request) int) Middleware
- func Metrics(metrics *expvar.Map, name string) Middleware
- func RateLimit(capacity, replenish float64, config *RateLimitConfig) Middleware
- func Recover(config *RecoverConfig) Middleware
- func SecurityHeaders(config *SecurityHeadersConfig) Middleware
- func Session(sm *session.Manager, errorHandler ErrorHandler) Middleware
- func Timeout(ttl time.Duration, config *TimeoutConfig) Middleware
- type RateLimitConfig
- type RecoverConfig
- type SecurityHeadersConfig
- type TimeoutConfig
- type Unwrapper
Constants ¶
const ( CSRFTokenCookieName = "__Host-csrf" CSRFTokenCookieNameInsecure = "csrf" CSRFTokenHeaderName = "x-csrf-token" CSRFTokenFieldName = "_csrf" )
const ( SessionCookieName = "__Host-session" SessionCookieNameInsecure = "session" )
Variables ¶
This section is empty.
Functions ¶
func MethodOverride ¶
func MethodOverride(next http.HandlerFunc) http.HandlerFunc
func NoContent ¶
func NoContent(next http.HandlerFunc) http.HandlerFunc
func RemoveTrailingSlash ¶
func RemoveTrailingSlash(next http.HandlerFunc) http.HandlerFunc
Types ¶
type ConsumeFunc ¶
type ErrorHandler ¶
type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
type IPWhitelistConfig ¶
type IPWhitelistConfig struct { IPs []string TrustedProxies []string ErrorHandler ErrorHandler }
type Middleware ¶
type Middleware func(next http.HandlerFunc) http.HandlerFunc
func CSRF ¶
func CSRF(errorHandler ErrorHandler) Middleware
func ETag ¶
func ETag(config *ETagConfig) Middleware
func IPWhitelist ¶
func IPWhitelist(config *IPWhitelistConfig) Middleware
func RateLimit ¶
func RateLimit(capacity, replenish float64, config *RateLimitConfig) Middleware
func Recover ¶
func Recover(config *RecoverConfig) Middleware
func SecurityHeaders ¶
func SecurityHeaders(config *SecurityHeadersConfig) Middleware
func Session ¶
func Session(sm *session.Manager, errorHandler ErrorHandler) Middleware
func Timeout ¶
func Timeout(ttl time.Duration, config *TimeoutConfig) Middleware
Timeout returns a new timeout middleware configured using the given TTL.
If any response is written/flushed, or if the request is hijacked then the timeout is ignored.
If the write deadline is set through an http.ResponseController then the timeout will be extended to just before that time if the original timeout would expire before then. Any error handlers should extend the write deadline if needed.
Any writes to the handler's ResponseWriter after the deadline will return an http.ErrHandlerTimeout if the timeout has not been ignored due to an earlier write before the deadline.
On timeout the configured error handler will be called to allow for a custom response, or a default gateway timeout response will be sent.
type RateLimitConfig ¶
type RateLimitConfig struct { Consume ConsumeFunc TrustedProxies []string ErrorHandler ErrorHandler }
type RecoverConfig ¶
type RecoverConfig struct { Logger func(r *http.Request) *slog.Logger ErrorHandler ErrorHandler }
type SecurityHeadersConfig ¶
type TimeoutConfig ¶
type TimeoutConfig struct { Logger func(r *http.Request) *slog.Logger ErrorHandler ErrorHandler }
type Unwrapper ¶
type Unwrapper interface {
Unwrap() http.ResponseWriter
}
Unwrapper is used to check that response writer wrappers implement the Unwrap method so they can be used by the http package's ResponseController to access features on the underlying original response writer, such as flushing, hijacking, etc.