Skip to main content

HttpClientBuilder

Struct HttpClientBuilder 

Source
pub struct HttpClientBuilder { /* private fields */ }
Available on crate feature 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

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for HttpClientBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoMaybeUndefined<T> for T

Source§

fn into_maybe_undefined(self) -> MaybeUndefined<T>

Converts this value into a three-state builder argument.
Source§

impl<T> IntoOption<T> for T

Source§

fn into_option(self) -> Option<T>

Converts this value into an optional builder argument.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more