pub struct Client { /* private fields */ }Expand description
A HTTP Client supporting HTTP/1.x and, when configured with a quic implementation, HTTP/3. See
Client::new and Client::new_with_quic for construction information.
Implementations§
Source§impl Client
impl Client
Sourcepub fn h2_idle_timeout(&self) -> Option<Duration>
pub fn h2_idle_timeout(&self) -> Option<Duration>
Returns a copy of Maximum idle time for a pooled HTTP/2 connection. None disables expiry.
Defaults to 5 minutes.
Sourcepub fn set_h2_idle_timeout(
&mut self,
h2_idle_timeout: Option<Duration>,
) -> &mut Client
pub fn set_h2_idle_timeout( &mut self, h2_idle_timeout: Option<Duration>, ) -> &mut Client
Sets Maximum idle time for a pooled HTTP/2 connection. None disables expiry., returning &mut Self for chaining
Defaults to 5 minutes.
Sourcepub fn with_h2_idle_timeout(self, h2_idle_timeout: Duration) -> Client
pub fn with_h2_idle_timeout(self, h2_idle_timeout: Duration) -> Client
Owned chainable setter for Maximum idle time for a pooled HTTP/2 connection. None disables expiry., returning Self
Defaults to 5 minutes.
Sourcepub fn without_h2_idle_timeout(self) -> Client
pub fn without_h2_idle_timeout(self) -> Client
Owned chainable setter for Maximum idle time for a pooled HTTP/2 connection. None disables expiry., returning Self
Defaults to 5 minutes.
Sourcepub fn h2_idle_ping_threshold(&self) -> Option<Duration>
pub fn h2_idle_ping_threshold(&self) -> Option<Duration>
Returns a copy of If a pooled HTTP/2 connection has been idle for longer than this, an active PING is
sent to verify it’s still alive before being handed out. None disables the probe.
Defaults to 10 seconds.
Sourcepub fn set_h2_idle_ping_threshold(
&mut self,
h2_idle_ping_threshold: Option<Duration>,
) -> &mut Client
pub fn set_h2_idle_ping_threshold( &mut self, h2_idle_ping_threshold: Option<Duration>, ) -> &mut Client
Sets If a pooled HTTP/2 connection has been idle for longer than this, an active PING is, returning &mut Self for chaining
sent to verify it’s still alive before being handed out. None disables the probe.
Defaults to 10 seconds.
Sourcepub fn with_h2_idle_ping_threshold(
self,
h2_idle_ping_threshold: Duration,
) -> Client
pub fn with_h2_idle_ping_threshold( self, h2_idle_ping_threshold: Duration, ) -> Client
Owned chainable setter for If a pooled HTTP/2 connection has been idle for longer than this, an active PING is, returning Self
sent to verify it’s still alive before being handed out. None disables the probe.
Defaults to 10 seconds.
Sourcepub fn without_h2_idle_ping_threshold(self) -> Client
pub fn without_h2_idle_ping_threshold(self) -> Client
Owned chainable setter for If a pooled HTTP/2 connection has been idle for longer than this, an active PING is, returning Self
sent to verify it’s still alive before being handed out. None disables the probe.
Defaults to 10 seconds.
Sourcepub fn h2_idle_ping_timeout(&self) -> Duration
pub fn h2_idle_ping_timeout(&self) -> Duration
Returns a copy of Timeout for the liveness PING sent under the h2_idle_ping_threshold policy.
Connections whose ACK doesn’t arrive within this window are treated as dead.
Defaults to 20 seconds.
Sourcepub fn set_h2_idle_ping_timeout(
&mut self,
h2_idle_ping_timeout: Duration,
) -> &mut Client
pub fn set_h2_idle_ping_timeout( &mut self, h2_idle_ping_timeout: Duration, ) -> &mut Client
Sets Timeout for the liveness PING sent under the h2_idle_ping_threshold policy., returning &mut Self for chaining
Connections whose ACK doesn’t arrive within this window are treated as dead.
Defaults to 20 seconds.
Sourcepub fn with_h2_idle_ping_timeout(self, h2_idle_ping_timeout: Duration) -> Client
pub fn with_h2_idle_ping_timeout(self, h2_idle_ping_timeout: Duration) -> Client
Owned chainable setter for Timeout for the liveness PING sent under the h2_idle_ping_threshold policy., returning Self
Connections whose ACK doesn’t arrive within this window are treated as dead.
Defaults to 20 seconds.
Sourcepub fn default_headers(&self) -> &Headers
pub fn default_headers(&self) -> &Headers
Borrows default request headers
Sourcepub fn set_timeout(&mut self, timeout: Duration) -> &mut Client
pub fn set_timeout(&mut self, timeout: Duration) -> &mut Client
Sets optional per-request timeout, returning &mut Self for chaining
Sourcepub fn with_timeout(self, timeout: Duration) -> Client
pub fn with_timeout(self, timeout: Duration) -> Client
Owned chainable setter for optional per-request timeout, returning Self
Sourcepub fn without_timeout(self) -> Client
pub fn without_timeout(self) -> Client
Owned chainable setter for optional per-request timeout, returning Self
Sourcepub fn context(&self) -> &HttpContext
pub fn context(&self) -> &HttpContext
Borrows configuration
Sourcepub fn context_mut(&mut self) -> &mut Arc<HttpContext>
pub fn context_mut(&mut self) -> &mut Arc<HttpContext>
Mutably borrow configuration
Sourcepub fn set_context(
&mut self,
context: impl Into<Arc<HttpContext>>,
) -> &mut Client
pub fn set_context( &mut self, context: impl Into<Arc<HttpContext>>, ) -> &mut Client
Sets configuration, returning &mut Self for chaining
Sourcepub fn with_context(self, context: impl Into<Arc<HttpContext>>) -> Client
pub fn with_context(self, context: impl Into<Arc<HttpContext>>) -> Client
Owned chainable setter for configuration, returning Self
Source§impl Client
impl Client
Sourcepub fn get(&self, url: impl IntoUrl) -> Conn
pub fn get(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the get http method and the provided url.
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::new(client_config());
let conn = client.get("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Get);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");Sourcepub fn post(&self, url: impl IntoUrl) -> Conn
pub fn post(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the post http method and the provided url.
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::new(client_config());
let conn = client.post("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Post);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");Sourcepub fn put(&self, url: impl IntoUrl) -> Conn
pub fn put(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the put http method and the provided url.
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::new(client_config());
let conn = client.put("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Put);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");Sourcepub fn delete(&self, url: impl IntoUrl) -> Conn
pub fn delete(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the delete http method and the provided url.
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::new(client_config());
let conn = client.delete("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Delete);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");Sourcepub fn patch(&self, url: impl IntoUrl) -> Conn
pub fn patch(&self, url: impl IntoUrl) -> Conn
Builds a new client conn with the patch http method and the provided url.
use trillium_client::{Client, Method};
use trillium_testing::client_config;
let client = Client::new(client_config());
let conn = client.patch("http://localhost:8080/some/route"); //<-
assert_eq!(conn.method(), Method::Patch);
assert_eq!(conn.url().to_string(), "http://localhost:8080/some/route");Sourcepub fn new_with_quic<C, Q>(connector: C, quic: Q) -> Clientwhere
C: Connector,
Q: QuicClientConfig<C>,
pub fn new_with_quic<C, Q>(connector: C, quic: Q) -> Clientwhere
C: Connector,
Q: QuicClientConfig<C>,
Build a new client with both a TCP connector and a QUIC connector for HTTP/3 support.
The connector’s runtime and UDP socket type are bound to the QUIC connector here,
before type erasure, so that trillium-quinn and the runtime adapter remain
independent crates that neither depends on the other.
When H3 is configured, the client will track Alt-Svc headers in responses and
automatically use HTTP/3 for subsequent requests to origins that advertise it.
Requests to origins without a cached alt-svc entry continue to use HTTP/1.1.
Sourcepub fn without_default_header(
self,
name: impl Into<HeaderName<'static>>,
) -> Client
pub fn without_default_header( self, name: impl Into<HeaderName<'static>>, ) -> Client
chainable method to remove a header from default request headers
Sourcepub fn with_default_header(
self,
name: impl Into<HeaderName<'static>>,
value: impl Into<HeaderValues>,
) -> Client
pub fn with_default_header( self, name: impl Into<HeaderName<'static>>, value: impl Into<HeaderValues>, ) -> Client
chainable method to insert a new default request header, replacing any existing value
Sourcepub fn default_headers_mut(&mut self) -> &mut Headers
pub fn default_headers_mut(&mut self) -> &mut Headers
borrow the default headers mutably
calling this will copy-on-write if the default headers are shared with another client clone
Sourcepub fn without_keepalive(self) -> Client
pub fn without_keepalive(self) -> Client
chainable constructor to disable http/1.1 connection reuse.
use trillium_client::Client;
use trillium_smol::ClientConfig;
let client = Client::new(ClientConfig::default()).without_keepalive();Sourcepub fn build_conn<M>(&self, method: M, url: impl IntoUrl) -> Conn
pub fn build_conn<M>(&self, method: M, url: impl IntoUrl) -> Conn
builds a new conn.
if the client has pooling enabled and there is an available connection to the dns-resolved socket (ip and port), the new conn will reuse that when it is sent.
use trillium_client::{Client, Method};
use trillium_smol::ClientConfig;
let client = Client::new(ClientConfig::default());
let conn = client.build_conn("get", "http://trillium.rs"); //<-
assert_eq!(conn.method(), Method::Get);
assert_eq!(conn.url().host_str().unwrap(), "trillium.rs");Sourcepub fn connector(&self) -> &ArcedConnector
pub fn connector(&self) -> &ArcedConnector
borrow the connector for this client
Sourcepub fn clean_up_pool(&self)
pub fn clean_up_pool(&self)
The pool implementation currently accumulates a small memory footprint for each new host. If your application is reusing a pool against a large number of unique hosts, call this method intermittently.
Sourcepub fn with_base(self, base: impl IntoUrl) -> Client
pub fn with_base(self, base: impl IntoUrl) -> Client
chainable method to set the base for this client
Sourcepub fn build_url(&self, url: impl IntoUrl) -> Result<Url, Error>
pub fn build_url(&self, url: impl IntoUrl) -> Result<Url, Error>
attempt to build a url from this IntoUrl and the Client::base, if set