mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-05 01:59:27 +00:00
The Responses WebSocket built its own rustls config from native roots, so it ignored ssl_verify, the CA bundle, the client certificate and HTTPS_PROXY/NO_PROXY. The upgrade GET now goes through a ClientVariant::WebSocket client (HTTP/1.1 only, no redirects) and tungstenite only frames the upgraded stream, since tungstenite has no proxy support (snapview/tungstenite-rs#177) tests/websocket.rs covers a private CA, ssl_verify off, mTLS, a CONNECT tunnel proxy, an h2-offering server, a refused upgrade and a wrong accept key Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5.5 KiB
5.5 KiB
Scope
- This crate is the one place a
reqwestclient is built.clippy.tomldisallowsreqwest::Client::new,Client::builderand the TLS builder methods everywhere else, so every outbound connection honors the host's TLS, proxy, keepalive and timeout settings by construction - Input is
HttpClientConfig, output is a pooledClient.Resolution::from(&HttpSettings)is the only way to turn user settings into anHttpClientConfig, and it is where names the user wrote (ssl_ecdh_curve,ssl_security_level) meet what rustls supports. A value rustls cannot honor keeps the default and is reported inResolution::unsupported, never silently dropped and never an error - Settings as the user writes them (
HttpSettings,HttpSettingsLayer,SslVerify,TcpKeepalive,EnvironmentProxies) live in../http-types, which links neither reqwest nor rustls. Crates that produce settings depend on that crate, not on this one - Route-neutral and Rust-only. Nothing here names a route, a provider, an API format, a credential or a config.yaml key. Provider credentials, OAuth, beta headers and model behavior are decided above and arrive as plain headers
gatewayandpython-bridgeare both hosts of this crate. Each lowers its own settings source into anHttpSettingsLayerand takes clients from one process-wideHttpClientPool
What lives here
pool.rs:HttpClientPool, keyed by(HttpClientConfig, ClientVariant)with a TTL.ClientVariantis the full list of ways a client may differ from the configured one (redirect policy, pinned DNS, dropped client certificate and proxies, HTTP/1.1 only for WebSocket). Add a variant only for a difference that must be fixed when the client is built, otherwise set it on the requestconfig.rsandtls.rs:HttpClientConfigtoreqwest::ClientBuilderand torustls::ClientConfigproxy.rs:EnvironmentProxiesto reqwest proxies, and the URL matcher the media fetcher uses to decide whether a URL leaves through the proxymedia.rs: the SSRF-safeMediaFetcher. It is here because address pinning is a build-time property of the client (dns_resolver2) and because it needs the proxy matcher.UrlPolicyandDownloadPolicyare the host's inputs, the host never decides a URL is safe on its ownrequest.rs: case-insensitive header helpers overVec<(String, String)>andHeaderPolicyfor forwarding. They keep existing precedence, duplicate handling and unrelated forwarded headers.string_headersandHeaderErrorvalidate the shape of a caller'sextra_headersand are the only place a request field is namedoutbound.rs:OutboundRequestserializes the body once and aRequestSignersees those exact bytes. A route builds it after its hooks ran and cannot change it afterwardstransport.rs:Error::{Http, Network, Connect}is the one transport error every crate above nests.Connectmeans the request never reached the provider, so a caller may reroute. Messages never carry URLswebsocket.rs: the WebSocket client handshake over a pooledClientVariant::WebSocketclient. reqwest sends the upgrade GET and owns TCP, TLS and proxies, so a WebSocket honorsssl_verify, the CA bundle, the client certificate andHTTPS_PROXY/NO_PROXYexactly like an HTTP call. tungstenite only frames the upgraded stream (from_raw_socket) and supplies the key and accept-key math. Never give tungstenite its own TCP or TLS connector (connect_async*, a rustls config, native roots): tungstenite has no proxy support (snapview/tungstenite-rs#177) and a second TLS stack drifts fromtls.rs- The WebSocket variant forces
http2: falsebecause an upgrade only exists in HTTP/1.1, and withh2in ALPN a server may pick h2 and the upgrade fails. Redirects are off, a WebSocket handshake never follows one - A refused upgrade is
transport::Error::Httpwith the status and body, a wrongSec-WebSocket-AcceptisNetwork, and anything before the request left (a bad URL or scheme included) isConnect mcp.rs: the connection the reqwest 0.12 builder cannot make. It repeats the builder chain for the reqwest 0.13 that rmcp needs, delete it when the two versions converge
Boundary with consumers
- Consumers take
litellm_http::Client, which derefs toreqwest::Client, and use reqwest's request and response types directly. This crate owns how a client is built and configured, it is not a wrapper over reqwest's request API - A consumer builds its request from the
Clientit was given. It never reads the environment, a config file or a settings snapshot to decide TLS, proxy or timeouts - Tests take
Client::for_test,plain_for_testorno_redirect_for_testbehind thetest-supportfeature. Production code never calls them
Tests
- Verify observable request behavior (which headers were sent, which proxy was picked, whether a client was reused), never helper structure
- TLS tests generate certificates with
rcgenand run a local listener. They never depend on a public host tests/websocket.rsis the transport contract for WebSockets. It runs a private CA with atokio-rustlsserver that offersh2in ALPN (so a client that offers h2 breaks the upgrade), an mTLS server, and a CONNECT tunnel proxy that records the tunnel target. Any change totls.rs,proxy.rsor the pool variants must keep it green, and a new TLS or proxy setting gets a case there too
references
- https://github.com/BerriAI/litellm-docs/blob/main/docs/guides/security_settings.md owns the user-facing meaning of
ssl_verify,ssl_certificate,ssl_security_levelandssl_ecdh_curve