middleware

package
v0.0.0-...-e9665ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CSRFTokenCookieName         = "__Host-csrf"
	CSRFTokenCookieNameInsecure = "csrf"
	CSRFTokenHeaderName         = "x-csrf-token"
	CSRFTokenFieldName          = "_csrf"
)
View Source
const (
	SessionCookieName         = "__Host-session"
	SessionCookieNameInsecure = "session"
)

Variables

This section is empty.

Functions

func Apply

func Apply(handler http.Handler, middlewares ...Middleware) http.Handler

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 ConsumeFunc func(r *http.Request) bool

type ETagConfig

type ETagConfig struct {
	Logger func(r *http.Request) *slog.Logger
}

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 MaxBytes

func MaxBytes(maxBytes func(*http.Request) int) Middleware

func Metrics

func Metrics(metrics *expvar.Map, name string) 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 SecurityHeadersConfig struct {
	Logger func(r *http.Request) *slog.Logger
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL