Documentation ¶
Overview ¶
Package webmiddleware provides middleware for http Handlers.
Index ¶
- func Chain(middlewares []MiddlewareFunc, handler http.Handler) http.Handler
- func GetSecureCookie(ctx context.Context) (secureCookie *securecookie.SecureCookie, err error)
- type Authenticator
- type CORSConfig
- type MiddlewareFunc
- func BasicAuth(realm string, authenticator Authenticator) MiddlewareFunc
- func CORS(config CORSConfig) MiddlewareFunc
- func CSRF(authKey []byte, opts ...csrf.Option) MiddlewareFunc
- func Conditional(middleware MiddlewareFunc, condition func(r *http.Request) bool) MiddlewareFunc
- func CookieAuth(cookieName string) MiddlewareFunc
- func Cookies(hashKey, blockKey []byte) MiddlewareFunc
- func FillContext(fillers ...fillcontext.Filler) MiddlewareFunc
- func Log(logger log.Interface, ignorePathsArray []string) MiddlewareFunc
- func MaxBody(maxBytes int64) MiddlewareFunc
- func Metadata(keys ...string) MiddlewareFunc
- func Namespace(value string) MiddlewareFunc
- func ProxyHeaders(config ProxyConfiguration) MiddlewareFunc
- func Recover() MiddlewareFunc
- func Redirect(config RedirectConfiguration) MiddlewareFunc
- func RequestID() MiddlewareFunc
- func RequestURL() MiddlewareFunc
- func SecurityHeaders() MiddlewareFunc
- type ProxyConfiguration
- type RedirectConfiguration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chain ¶ added in v3.8.2
func Chain(middlewares []MiddlewareFunc, handler http.Handler) http.Handler
Chain returns a http.Handler that chains the middleware onion-style around the handler.
func GetSecureCookie ¶ added in v3.9.0
func GetSecureCookie(ctx context.Context) (secureCookie *securecookie.SecureCookie, err error)
GetSecureCookie retrieves the secure cookie encoder from the context.
Types ¶
type Authenticator ¶
type Authenticator interface { // Authenticate the user with the given password and return true if successful. // An error may be returned if an internal error occurred. Authenticate(username, password string) (ok bool, err error) }
Authenticator is the interface the Basic Auth middleware uses to authenticate users.
func AuthUser ¶
func AuthUser(username, password string) Authenticator
AuthUser is the same as AuthUsers, but for a single user.
func AuthUsers ¶
func AuthUsers(usernamesPasswords map[string]string) Authenticator
AuthUsers authenticates users with the given map[username]password.
type CORSConfig ¶
type CORSConfig struct { AllowedHeaders []string AllowedMethods []string AllowedOrigins []string ExposedHeaders []string MaxAge int AllowCredentials bool }
CORSConfig is the configuration for the CORS middleware.
type MiddlewareFunc ¶
MiddlewareFunc is a function that acts as middleware for http Handlers.
func BasicAuth ¶
func BasicAuth(realm string, authenticator Authenticator) MiddlewareFunc
BasicAuth returns a middleware that authenticates users with Basic Auth.
func CORS ¶
func CORS(config CORSConfig) MiddlewareFunc
CORS returns a middleware that handles Cross-Origin Resource Sharing.
func CSRF ¶ added in v3.9.0
func CSRF(authKey []byte, opts ...csrf.Option) MiddlewareFunc
CSRF returns a middleware that enables CSRF protection via a sync token. The skipCheck parameter can be used to skip CSRF protection based on the request interface.
func Conditional ¶ added in v3.9.0
func Conditional(middleware MiddlewareFunc, condition func(r *http.Request) bool) MiddlewareFunc
Conditional is a middleware that only executes middleware if the condition returns true for the request. If the condition returns false, the middleware is skipped, and request handling moves on to the next handler in the chain.
func CookieAuth ¶ added in v3.9.0
func CookieAuth(cookieName string) MiddlewareFunc
CookieAuth extracts the auth cookie and forwards it to the Authorization header.
func Cookies ¶ added in v3.9.0
func Cookies(hashKey, blockKey []byte) MiddlewareFunc
Cookies is a middleware that allows handling of secure cookies.
func FillContext ¶
func FillContext(fillers ...fillcontext.Filler) MiddlewareFunc
FillContext returns a middleware that fills global context into a call context.
func Log ¶
func Log(logger log.Interface, ignorePathsArray []string) MiddlewareFunc
Log returns a middleware that logs requests. If logger is nil, the logger will be extracted from the context.
func MaxBody ¶
func MaxBody(maxBytes int64) MiddlewareFunc
MaxBody returns a middleware that limits the maximum body of requests.
func Metadata ¶
func Metadata(keys ...string) MiddlewareFunc
Metadata returns a middleware that sets gRPC metadata from the request headers.
func Namespace ¶ added in v3.8.2
func Namespace(value string) MiddlewareFunc
Namespace is middleware that sets the namespace.
func ProxyHeaders ¶
func ProxyHeaders(config ProxyConfiguration) MiddlewareFunc
ProxyHeaders processes proxy headers for trusted proxies.
func Redirect ¶
func Redirect(config RedirectConfiguration) MiddlewareFunc
Redirect returns a middleware that redirects requests if they don't already match the configuration.
func RequestID ¶
func RequestID() MiddlewareFunc
RequestID returns a middleware that inserts a request ID into each request.
func RequestURL ¶
func RequestURL() MiddlewareFunc
RequestURL populates (*http.Request).URL with the scheme and host.
func SecurityHeaders ¶
func SecurityHeaders() MiddlewareFunc
SecurityHeaders returns a middleware that inserts security headers into each response.
type ProxyConfiguration ¶
ProxyConfiguration is the configuration for the ProxyHeaders middleware.
func (*ProxyConfiguration) ParseAndAddTrusted ¶
func (c *ProxyConfiguration) ParseAndAddTrusted(cidrs ...string) error
ParseAndAddTrusted parses a list of CIDRs and adds them to the list of trusted ranges.
type RedirectConfiguration ¶
type RedirectConfiguration struct { Scheme func(string) string HostName func(string) string Port func(uint) uint Path func(string) string Code int }
RedirectConfiguration is the configuration for the Redirect middleware. If any of Scheme, HostName, Port, Path returns a different value than the argument passed to it, the middleware will redirect with the configured Code.