Documentation
¶
Overview ¶
Package middlewares provides HTTP middleware for the Gate server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChiRouteLabeler ¶ added in v1.0.4
ChiRouteLabeler attaches the matched chi route pattern as the "http.route" attribute on the active otelhttp span. It must run after otelhttp.NewMiddleware so the labeler is present in the request context.
func NormalizePath ¶ added in v1.0.5
NormalizePath is an HTTP middleware that strips trailing slashes from r.URL.Path (and r.URL.RawPath, when set) before the request reaches subsequent middleware or handlers. The root path "/" is preserved.
Why this exists: chi's middleware.StripSlashes only rewrites the chi RouteContext's RoutePath; it does not modify r.URL.Path. Middleware that reads r.URL.Path directly (for example middleware.Heartbeat, structured loggers, or OpenTelemetry span-name formatters) therefore continues to see the unnormalized path. Registering NormalizePath at the top of the chain closes that gap so every downstream observer sees a single canonical path.
NormalizePath does not mutate the caller's *http.Request. If normalization is required it performs a shallow clone of the request and its URL (mirroring net/http.StripPrefix); otherwise it forwards the request unchanged.
func OriginVerify ¶
OriginVerify creates middleware that validates requests contain a shared secret header. Uses constant-time comparison to prevent timing attacks.
When origin verification is disabled via config, the middleware is a no-op. Returns 403 Forbidden when the header is missing or the value doesn't match.
Types ¶
This section is empty.