middleware

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package middleware contains HTTP middlewares that wrap a HTTP handler to provide ancillary functionality such as capturing HTTP details into the request context or printing debug information on incoming requests.

Index

Constants

View Source
const (
	// RequestMethodKey is the request context key used to store r.Method created by
	// the PopulateRequestContext middleware.
	RequestMethodKey ctxKey = iota + 1

	// RequestURIKey is the request context key used to store r.RequestURI created by
	// the PopulateRequestContext middleware.
	RequestURIKey

	// RequestPathKey is the request context key used to store r.URL.Path created by
	// the PopulateRequestContext middleware.
	RequestPathKey

	// RequestProtoKey is the request context key used to store r.Proto created by
	// the PopulateRequestContext middleware.
	RequestProtoKey

	// RequestHostKey is the request context key used to store r.Host created by
	// the PopulateRequestContext middleware.
	RequestHostKey

	// RequestRemoteAddrKey is the request context key used to store r.RemoteAddr
	// created by the PopulateRequestContext middleware.
	RequestRemoteAddrKey

	// RequestXForwardedForKey is the request context key used to store the
	// X-Forwarded-For header created by the PopulateRequestContext middleware.
	RequestXForwardedForKey

	// RequestXForwardedProtoKey is the request context key used to store the
	// X-Forwarded-Proto header created by the PopulateRequestContext middleware.
	RequestXForwardedProtoKey

	// RequestXRealIPKey is the request context key used to store the
	// X-Real-IP header created by the PopulateRequestContext middleware.
	RequestXRealIPKey

	// RequestAuthorizationKey is the request context key used to store the
	// Authorization header created by the PopulateRequestContext middleware.
	RequestAuthorizationKey

	// RequestRefererKey is the request context key used to store Referer header
	// created by the PopulateRequestContext middleware.
	RequestRefererKey

	// RequestUserAgentKey is the request context key used to store the User-Agent
	// header created by the PopulateRequestContext middleware.
	RequestUserAgentKey

	// RequestXRequestIDKey is the request context key used to store the X-Request-Id
	// header created by the PopulateRequestContext middleware.
	RequestXRequestIDKey

	// RequestAcceptKey is the request context key used to store the Accept header
	// created by the PopulateRequestContext middleware.
	RequestAcceptKey

	// RequestXCSRFTokenKey is the request context key used to store X-Csrf-Token header
	// created by the PopulateRequestContext middleware.
	RequestXCSRFTokenKey
)

Variables

This section is empty.

Functions

func Debug

func Debug(mux loomhttp.Muxer, w io.Writer) func(http.Handler) http.Handler

Debug returns a debug middleware which prints detailed information about incoming requests and outgoing responses including all headers, parameters and bodies.

func PopulateRequestContext

func PopulateRequestContext() func(http.Handler) http.Handler

PopulateRequestContext returns a middleware which populates a number of standard HTTP header values into the request context. Those values may be extracted using the corresponding ContextKey type in this package.

func RequestContext

func RequestContext(ctx context.Context) func(http.Handler) http.Handler

RequestContext returns a middleware which initializes the request context.

func RequestContextKeyVals

func RequestContextKeyVals(keyvals ...any) func(http.Handler) http.Handler

RequestContextKeyVals returns a middleware which adds the given key/value pairs to the request context.

func SmartRedirectSlashes

func SmartRedirectSlashes(next http.Handler) http.Handler

SmartRedirectSlashes is a middleware that matches the request path with patterns added to the router and redirects it.

If a pattern is added to the router with a trailing slash, any matches on that pattern without a trailing slash will be redirected to the version with the slash. If a pattern does not have a trailing slash, matches on that pattern with a trailing slash will be redirected to the version without.

This middleware depends on chi, so it needs to be mounted on chi's router. It make the router behavior similar to httptreemux.

Types

This section is empty.

Directories

Path Synopsis
Package otel provides thin OpenTelemetry middleware helpers for Loom HTTP servers and clients.
Package otel provides thin OpenTelemetry middleware helpers for Loom HTTP servers and clients.

Jump to

Keyboard shortcuts

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