Skip to main content

Module proxy

Module proxy 

Source
Expand description

Proxy-aware HTTP clients with Go net/http semantics, shared by every executor (helps/proxy_helpers.go, sdk/proxyutil, net/http client behaviour; M4-0029).

  • Proxy: the effective proxy for a request (credential, then requests.proxy-url), parsed like proxyutil.Parse.
  • GoClients: clients keyed by effective proxy in a bounded 64-entry LRU, with Go’s standard-transport proxy rules (empty inherits environment proxies, direct and none bypass them, an unusable URL falls back to the default transport).
  • send and GoHeaders: one exchange the way http.Client.Do performs it: HTTP/1.1 header line order, custom Host, manual redirects with Referer and credential stripping, and transparent gzip only when Go would have asked for it.
  • lines: bufio.Scanner line semantics for event streams.

Claude’s first-party Node/OpenSSL profile lives in tls.rs; it uses Proxy and Hooks from here so both kinds of client share proxy and test routing.

ponytail: no request-scoped proxy override (Go RequestProxyURL / opts.ProxyURL); ExecRequest carries none. Add a field to the execution envelope when a route needs it.

Structs§

GoClients
Go standard-transport clients keyed by effective proxy, most recently used first.
GoHeaders
Headers in the order Go’s HTTP/1.1 client writes them: Host, User-Agent (Go’s default when unset), Content-Length, the remaining request headers sorted by key with their values in order, then the transport’s Accept-Encoding.
Hooks
Test-only routing: extra trust roots replace the default store, and resolve overrides pin logical hosts to local addresses while URL, Host and SNI stay unchanged. Production uses Hooks::default.
RawUpstream
Upstream with the transport’s raw body errors and the response’s protocol version (Go’s response reader keeps framing headers by version).
Route
How one request hop is sent: its client, and an exact header order for Claude’s native transport (None is Go net/http’s order). Go’s http.Client picks the round tripper per hop, so a redirect can change both.
Upstream
A response with Go net/http semantics: the body is decoded only for gzip the transport requested itself, and is never framed or buffered here.

Enums§

Proxy
Effective proxy for one request (effectiveProxyURL + proxyutil.Parse).
SendError
Why send_request_raw failed: the transport’s own error (which may name the URL, so callers decide what to show), a locally generated one, or Timeout: the deadline passed before a hop was sent, so nothing was sent, and callers report it as they report the transport’s own timeout. url is the URL Go’s client names in its *url.Error: the failing hop (the caller’s URL as written for the first request), or the rejected Location when the redirect limit is hit.

Constants§

MAX_ERROR_BODY
Largest error body kept from an upstream rejection.

Functions§

canonical_header
Go textproto.CanonicalMIMEHeaderKey.
default_client
A plain client whose redirects are followed by send, not by wreq, with Go’s environment proxy rules.
go_target
The request Go sends for url: its scheme and authority as written, then URL.RequestURI(). None where Go fails (no host, an opaque URL included: http::Uri needs one too) or wreq would not send that: a host Go escapes or IDNA-encodes on the way out (a percent escape, which includes an IPv6 zone, or a non-ASCII byte), or a target http::Uri does not carry as written (given a string, wreq would re-parse and normalize it).
lines
bufio.Scanner with ScanLines and Buffer(nil, max): one item per line without its \n, a trailing \r dropped, the final unterminated line included, and bufio.ErrTooLong when no newline falls within max bytes of a line’s start (the scanner’s buffer never holds more). An I/O error ends the stream after the line buffered before it, as Scan returns that last token before reporting Err.
read_all
io.ReadAll up to limit bytes; with lossy, a read error keeps what arrived (Go’s error paths ignore it).
redact
proxyutil.Redact: a proxy URL safe for logs (no user info).
request
send for any method: http.NewRequest(method, url, body) then Client.Do, with Go’s redirect rules for that method (a GET follows 301-303 and 307/308 as a GET). None is Go’s nil body.
request_once
request without following redirects: a client whose CheckRedirect returns http.ErrUseLastResponse hands back the first answer, 3xx included. Untimed: it reports no stages (Antigravity’s grounding redirects).
send
POSTs body the way Go’s http.Client.Do does, following redirects itself: at most ten requests, 301/302/303 turn a POST into a body-less GET, 307/308 resend the body, the initial headers are copied to every hop (credentials only within the original domain), a custom Host survives only relative redirects, and the previous URL becomes Referer. timeout bounds the exchange.
send_request
send_routed for any method. None is Go’s nil body: no body and no Content-Length (management api-call).
send_request_raw
send_request without error sanitising, for callers that report Go’s own error text (the plugin host’s host.http.*).
send_routed
send with the client and header order chosen per hop. With timing, the exchange reports its stages to the attempt’s usage record (UpstreamStage).
send_scanned
send for a response body the caller reads line by line: a body cut short fails with Go’s unexpected EOF (RawUpstream::scanned).

Type Aliases§

SharedGoClients
Shared handle for executors: Go clients plus the hooks used to build them.