Documentation
¶
Overview ¶
Package httpmw holds net/http middleware and helpers shared by relay's listeners: request body size limits, client IP resolution behind trusted proxies, and browser security headers.
Index ¶
Constants ¶
const DefaultMaxRequestBytes int64 = 32 * 1024 * 1024
DefaultMaxRequestBytes matches Anthropic's documented /v1/messages limit (32 MB). OpenAI/Gemini limits are similar or higher; we standardize on this so relay never rejects a body the upstream would accept. Override with RELAY_MAX_REQUEST_BYTES.
Variables ¶
This section is empty.
Functions ¶
func ClientIP ¶ added in v0.10.0
ClientIP resolves the caller's address: the rightmost X-Forwarded-For hop that is not itself a trusted proxy when the peer is one, RemoteAddr otherwise. Walking from the right is what makes the result unspoofable — a client-supplied prefix can never win.
func IsBodyTooLargeError ¶
func SecurityHeaders ¶ added in v0.10.1
SecurityHeaders sets browser hardening headers for a listener that serves browser-facing JSON: no framing, no MIME sniffing, no cross-origin referrer, and a CSP that lets a response render nothing. Handlers that serve HTML set their own Content-Security-Policy over this default.
func TrustedProxies ¶ added in v0.10.0
TrustedProxies parses RELAY_TRUSTED_PROXIES (comma-separated IPs or CIDRs) once per process. Empty means no proxy is trusted, so ClientIP ignores forwarding headers entirely.
Types ¶
This section is empty.