httpheader

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 3 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 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

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

	// 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.

Variables

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

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

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

func Match(name string, patterns []string) bool

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

func SafeUpstreamError(providerName string, err error) string

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

func SanitizeUpstreamResponse(h http.Header) http.Header

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.

func Strip

func Strip(h http.Header) http.Header

Strip removes relay-internal control headers and hop-by-hop headers from h. Applied once at the inference edge, after the mode classifier has captured what it needs into ctx. Returns the same map for chaining.

Types

This section is empty.

Jump to

Keyboard shortcuts

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