httpmw

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func ClientIP(r *http.Request, trusted []*net.IPNet) string

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 IsBodyTooLargeError(err error) bool

func LimitBody

func LimitBody(limit int64) func(http.Handler) http.Handler

func SecurityHeaders added in v0.10.1

func SecurityHeaders(next http.Handler) http.Handler

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

func TrustedProxies() []*net.IPNet

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.

Jump to

Keyboard shortcuts

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