pub struct SwappableClient { /* private fields */ }Expand description
Config-swappable distributor of reqwest::Client instances.
Cloning a SwappableClient shares the same underlying state. Calling
Self::swap or Self::update builds the replacement clients up front
and atomically publishes them: in-flight requests retain their previously
cloned reqwest::Client until completion, while new requests receive the
updated client.
Implementations§
Source§impl SwappableClient
impl SwappableClient
Sourcepub fn new(config: HttpClientConfig) -> Result<Self>
pub fn new(config: HttpClientConfig) -> Result<Self>
Builds a new SwappableClient from the provided HttpClientConfig.
Sourcepub fn try_default() -> Result<Self>
pub fn try_default() -> Result<Self>
Builds a new SwappableClient using HttpClientConfig::default.
Sourcepub fn from_client(client: Client) -> Self
pub fn from_client(client: Client) -> Self
Wraps an already-built reqwest::Client.
Both Self::client and Self::no_redirect_client return clones of
client until Self::swap or Self::update replaces the state.
Sourcepub fn with_headers(self, headers: HeaderMap) -> Self
pub fn with_headers(self, headers: HeaderMap) -> Self
Replaces per-handle headers attached to requests created via Self::get,
while continuing to share the underlying hot-swappable client state.
Sourcepub fn with_header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn with_header(self, name: HeaderName, value: HeaderValue) -> Self
Inserts a per-handle header attached to requests created via Self::get,
while continuing to share the underlying hot-swappable client state.
Sourcepub fn scoped_headers(&self) -> &HeaderMap
pub fn scoped_headers(&self) -> &HeaderMap
Returns the per-handle headers attached by Self::get.
Sourcepub fn request(&self, method: Method, url: impl IntoUrl) -> RequestBuilder
pub fn request(&self, method: Method, url: impl IntoUrl) -> RequestBuilder
Starts an HTTP request using the active reqwest::Client and this handle’s scoped headers.
Sourcepub fn get(&self, url: impl IntoUrl) -> RequestBuilder
pub fn get(&self, url: impl IntoUrl) -> RequestBuilder
Starts a GET request using the active reqwest::Client and this handle’s scoped headers.
Sourcepub fn config(&self) -> HttpClientConfig
pub fn config(&self) -> HttpClientConfig
Returns a clone of the currently active HttpClientConfig.
Sourcepub fn no_redirect_client(&self) -> Client
pub fn no_redirect_client(&self) -> Client
Returns a cheap clone of the currently active no-redirect reqwest::Client.
Sourcepub fn swap(&self, config: HttpClientConfig) -> Result<()>
pub fn swap(&self, config: HttpClientConfig) -> Result<()>
Builds replacement clients from config and swaps them in atomically.
If building either client fails, the previous clients remain active.
Sourcepub fn swap_client(&self, client: Client)
pub fn swap_client(&self, client: Client)
Replaces the active reqwest::Client directly with an already-built instance.
Sourcepub fn update<F>(&self, configure: F) -> Result<()>
pub fn update<F>(&self, configure: F) -> Result<()>
Clones the active HttpClientConfig, transforms it with configure,
and swaps in the rebuilt clients.
If building fails, the previous configuration and clients remain active.