pub struct HttpClientBuilder { /* private fields */ }client only.Expand description
Configures an HttpClient before its underlying HTTP client is built.
Use HttpClient::builder for a base URL or
HttpClient::builder_with_endpoint for an exact endpoint.
Implementations§
Source§impl HttpClientBuilder
impl HttpClientBuilder
Sourcepub fn configure_http(
self,
configure: impl FnOnce(ClientBuilder) -> ClientBuilder,
) -> Self
pub fn configure_http( self, configure: impl FnOnce(ClientBuilder) -> ClientBuilder, ) -> Self
Customize the HTTP client used for HTTP/SSE or the WebSocket handshake.
Each call transforms the current configuration, retaining previous changes. Configure default headers, proxies, DNS, trust roots, client certificates, and timeouts through reqwest’s builder rather than building a client first.
For WebSockets, Self::build overrides the HTTP version preference with
HTTP/1.1 and disables redirects. HTTP/SSE retains the supplied settings.
Subprotocols and extensions are not negotiated, even if custom default
headers request them.
§Proxy headers
Do not set Host, Connection, Upgrade, or any Sec-WebSocket-* header
through reqwest::Proxy::headers for WebSocket clients. The SDK sets
Connection, Upgrade, Sec-WebSocket-Version, and Sec-WebSocket-Key
over default_headers, but reqwest can overwrite them
afterward with proxy headers on plain ws:// connections. The SDK cannot
inspect or reject this opaque proxy configuration at build time.
Response validation still runs before sending ACP data; it does not prove
that proxy configuration left every request header unchanged.
§Defaults
Both transports use reqwest’s proxy discovery and TLS verification defaults.
This changes unconfigured WebSockets from direct connections with bundled
WebPKI roots to environment proxies (and system proxies when enabled) and,
with the SDK’s rustls configuration, platform certificate verification.
Use http.no_proxy() to connect directly. Use tls_certs_only for an
explicit root set, or tls_certs_merge to add roots to the default trust:
use agent_client_protocol_http::HttpClient;
fn direct_with_root(root_pem: &[u8]) -> Result<HttpClient, Box<dyn std::error::Error>> {
let root = reqwest::Certificate::from_pem(root_pem)?;
Ok(HttpClient::builder("wss://agent.example")
.configure_http(|http| http.no_proxy().tls_certs_only([root]))
.build()?)
}§Timeouts
Reqwest request/read timeouts apply to the WebSocket opening handshake, not the lifetime of the upgraded socket. For HTTP/SSE, they retain their normal reqwest request/body semantics, including long-lived SSE bodies.
§Preconfigured TLS
Prefer reqwest’s TLS options for custom roots and identities. If using
tls_backend_preconfigured, its ALPN configuration must itself use
HTTP/1.1 for WebSockets: reqwest cannot rewrite a preconfigured backend’s
ALPN. Incompatible negotiation is rejected before transmitting ACP data.
Sourcepub fn build(self) -> Result<HttpClient, HttpClientError>
pub fn build(self) -> Result<HttpClient, HttpClientError>
Build a client, applying the selected transport’s connection policies.
Accepts http, https, ws, and wss URLs. No connection is opened
until the resulting HttpClient is connected through ConnectTo.