pub struct HttpClient { /* private fields */ }client only.Expand description
An endpoint-bound ACP transport using HTTP/SSE or WebSocket.
Cloning shares the underlying HTTP connection pool. Each connection has independent ACP transport state.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(base_url: impl AsRef<str>) -> Result<Self, HttpClientError>
pub fn new(base_url: impl AsRef<str>) -> Result<Self, HttpClientError>
Create a client from a base URL and target the standard ACP endpoint.
If the URL path is empty, /acp is used. Otherwise /acp is appended
unless the path already ends with /acp.
Use Self::builder to customize headers, TLS, proxies, or timeouts.
Sourcepub fn with_endpoint(endpoint: impl AsRef<str>) -> Result<Self, HttpClientError>
pub fn with_endpoint(endpoint: impl AsRef<str>) -> Result<Self, HttpClientError>
Create a client that targets the exact endpoint URL.
Use this when connecting to a server configured with a custom
ServerOptions::path. Use Self::builder_with_endpoint to also
customize the HTTP client configuration.
Sourcepub fn builder(base_url: impl AsRef<str>) -> HttpClientBuilder
pub fn builder(base_url: impl AsRef<str>) -> HttpClientBuilder
Configure a client from a base URL targeting the standard ACP endpoint.
Uses the same path normalization as Self::new. Invalid URLs and
unsupported schemes are reported by HttpClientBuilder::build.
use std::time::Duration;
use agent_client_protocol_http::HttpClient;
let transport = HttpClient::builder("wss://agent.example")
.configure_http(|http| {
http.connect_timeout(Duration::from_secs(5))
.timeout(Duration::from_secs(10))
})
.build()?;Sourcepub fn builder_with_endpoint(endpoint: impl AsRef<str>) -> HttpClientBuilder
pub fn builder_with_endpoint(endpoint: impl AsRef<str>) -> HttpClientBuilder
Configure a client targeting an exact endpoint URL without changing its path.
Use this when connecting to a server configured with a custom
ServerOptions::path. Invalid URLs and unsupported schemes are reported
by HttpClientBuilder::build.
Sourcepub fn from_http_client(
endpoint: impl AsRef<str>,
http: Client,
) -> Result<Self, HttpClientError>
pub fn from_http_client( endpoint: impl AsRef<str>, http: Client, ) -> Result<Self, HttpClientError>
Reuse an existing reqwest client for HTTP/SSE at an exact endpoint URL.
The path is not changed: include /acp or the server’s custom path.
This preserves the supplied client’s configuration and connection pool.
Only http:// and https:// URLs are accepted. For WebSockets, use
Self::builder or Self::builder_with_endpoint so this transport can
configure HTTP/1.1 and disable handshake redirects before building the
underlying client.
Sourcepub fn with_client(
base_url: impl AsRef<str>,
http: Client,
) -> Result<Self, HttpClientError>
👎Deprecated: Use builder(…).configure_http(…).build(), or from_http_client with an exact HTTP/SSE endpoint
pub fn with_client( base_url: impl AsRef<str>, http: Client, ) -> Result<Self, HttpClientError>
Use builder(…).configure_http(…).build(), or from_http_client with an exact HTTP/SSE endpoint
Reuse an existing HTTP/SSE client with the standard ACP endpoint.
Preserves the same base-URL path normalization as Self::new.
WebSocket URLs return HttpClientError::WebSocketRequiresBuilder
before any network I/O; migrate those calls to Self::builder.
Sourcepub fn with_endpoint_and_client(
endpoint: impl AsRef<str>,
http: Client,
) -> Result<Self, HttpClientError>
👎Deprecated: Use builder_with_endpoint(…).configure_http(…).build(), or from_http_client for an existing HTTP/SSE client
pub fn with_endpoint_and_client( endpoint: impl AsRef<str>, http: Client, ) -> Result<Self, HttpClientError>
Use builder_with_endpoint(…).configure_http(…).build(), or from_http_client for an existing HTTP/SSE client
Reuse an existing HTTP/SSE client at an exact endpoint.
WebSocket URLs return HttpClientError::WebSocketRequiresBuilder
before any network I/O; migrate those calls to
Self::builder_with_endpoint.