middlewares

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

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

func ChiRouteLabeler(next http.Handler) http.Handler

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

func NormalizePath(next http.Handler) http.Handler

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

func OriginVerify(cfg config.OriginConfig) func(http.Handler) http.Handler

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.

func SecurityHeaders

func SecurityHeaders(next http.Handler) http.Handler

SecurityHeaders adds OWASP-recommended security headers to responses. HSTS header is only added when the request is served over TLS.

Types

This section is empty.

Jump to

Keyboard shortcuts

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