httpheader

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

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"
)

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.

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