Documentation
¶
Overview ¶
Package httpheader holds the header sets applied at relay's HTTP edges: what is stripped from inbound requests before forwarding, what is removed from upstream responses, and what an upstream failure may carry onto the error relay writes.
Index ¶
Constants ¶
const ( HeaderRelayAPIKey = "X-Wr-Api-Key" HeaderProxyMode = "X-Wr-Proxy-Mode" HeaderUpstreamHost = "X-Wr-Upstream-Host" ProxyModeValueProxy = "Proxy" // HeaderUsage opts the caller into an inline relay_usage block on the // response ("full"). Relay-internal; stripped from the upstream // request by the X-WR-* denylist. HeaderUsage = "X-Wr-Usage" UsageValueFull = "full" // HeaderEventTime overrides the usage Event timestamp (RFC3339). // Honored only under RELAY_DEV_TRUST_EVENT_TIME=1 — dev/replay // tooling. Stripped from the upstream request by the X-WR-* denylist. HeaderEventTime = "X-Wr-Event-Time" // HeaderRequestTags carries caller-supplied observability tags as a // flat JSON object (string→string). Validated post-flight and landed // on the usage Event's tags field. Stripped from the upstream request // by the X-WR-* denylist. HeaderRequestTags = "X-Wr-Request-Tags" // HeaderClient names the calling client profile (e.g. "claude-code") // explicitly, ahead of path-prefix and User-Agent detection. Stripped // from the upstream request by the X-WR-* denylist. HeaderClient = "X-Wr-Client" // HeaderWarnings is a response header carrying non-fatal request // adjustments the relay made (e.g. params stripped because the routed // model declares them unsupported) so drops are surfaced, never silent. HeaderWarnings = "X-Wr-Warnings" // HeaderTokenCount is a response header naming how an input-token count was arrived at: "exact" from the upstream's own counter, "calibrated" from the ratio relay measured on this session's or model's traffic, "estimated" from bytes alone. A caller that cares about precision can tell the three apart. HeaderTokenCount = "X-Wr-Token-Count" // HeaderContentCapture is the OTLP receiver's response header saying whether it stores the message content of this credential's calls, so a reporting client neither withholds what a policy wants nor uploads what relay drops. HeaderContentCapture = "X-Wr-Content-Capture" ContentCaptureStore = "store" // the governing policy stores content ContentCaptureDrop = "drop" // the governing policy or an operator switch does not ContentCaptureClient = "client" // no policy governs; the client's opt-in decides // HeaderShouldRetry tells the caller whether retrying this exact request can succeed. Some SDKs trust it over their own status heuristics, so relay emits it on every error it writes rather than leaving a forwarded upstream error as the only response that carries one. HeaderShouldRetry = "X-Should-Retry" )
Relay-internal control headers. Read at the inference edge by the mode classifier; never forwarded upstream. Spelled in canonical form so Header.Get/Set/Del skip re-canonicalizing into a fresh string.
Variables ¶
var HopByHop = []string{
"Connection",
"Keep-Alive",
"Proxy-Authenticate",
"Proxy-Authorization",
"Te",
"Trailers",
"Transfer-Encoding",
"Upgrade",
}
HopByHop is the canonical RFC 7230 hop-by-hop header set.
var StripDenylist = []string{
"Authorization",
"X-Api-Key",
"Cookie",
"X-WR-*",
}
StripDenylist is the negative strip set applied at the inference edge after the mode classifier has captured the relay-internal headers it needs. Everything else passes through to upstream — the relay does not police which vendor-specific headers callers send.
Authorization is denylisted at the edge for both modes:
- Normal mode: relay-key value, consumed by auth; adapter injects the upstream key on the outbound request.
- Proxy mode: caller's upstream key, captured by the classifier; the proxy forwarder re-attaches it on the outbound request.
Either way, ctx is the source of truth post-strip; nothing reads the raw inbound Authorization downstream.
Matching is case-insensitive. Trailing "*" is a prefix match.
var UpstreamErrorAllowlist = []string{ "Retry-After", HeaderShouldRetry, "X-Request-Id", "Content-Type", "Anthropic-Ratelimit-*", "X-Ratelimit-*", }
UpstreamErrorAllowlist is the set copied from a failed upstream response onto the error relay writes in its place: backoff timing, quota counters, the provider's request id for support tickets, and the content type describing the forwarded bytes. Deliberately narrow — Content-Length would misdescribe what relay writes, Set-Cookie and hop-by-hop headers leak provider transport state into a relay response.
Functions ¶
func Match ¶
Match reports whether name matches any pattern in patterns, case-insensitively. Patterns may be exact (e.g., "Authorization") or prefix-style with a trailing "*" (e.g., "X-WR-*").
func SafeUpstreamError ¶
SafeUpstreamError returns a user-safe error message for an upstream failure, redacting URLs, IP addresses, and other internal details. providerName is the public provider identifier (e.g. "openai").
func SanitizeUpstreamResponse ¶
SanitizeUpstreamResponse strips hop-by-hop headers from the upstream response before they are propagated back to the caller. Modifies h in place. Returns the same map.
Types ¶
This section is empty.