pub struct HttpClient { /* private fields */ }Expand description
An asynchronous HTTP client with rate limiting, timeouts, and custom headers.
The client uses Hyper for normal I/O and supports default and per-key quotas. Multiple
clients can share the same rate limiter when their requests consume one quota budget.
With simulation and cfg(madsim), plaintext HTTP/1.1 uses simulated byte streams;
HTTPS, explicit proxies, and redirect following are unsupported.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub async fn request(
&self,
method: Method,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request( &self, method: Method, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub async fn request_with_secret_body(
&self,
method: Method,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: SecretString,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request_with_secret_body( &self, method: Method, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: SecretString, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request whose body contains secret material.
The body retains its zeroizing owner until the transport releases the last byte buffer. Transport, TLS, and operating-system layers may make additional plaintext copies that this client cannot zeroize.
§Errors
Returns an error if unable to send the request or if it times out.
Sourcepub async fn request_with_url_redacted(
&self,
method: Method,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request_with_url_redacted( &self, method: Method, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request while redacting the URL from logs and transport errors.
Use this for endpoints whose path or other URL components can carry credentials.
§Errors
Returns an error if unable to send request or times out.
Sourcepub async fn request_with_params<P: Serialize>(
&self,
method: Method,
url: String,
params: Option<&P>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request_with_params<P: Serialize>( &self, method: Method, url: String, params: Option<&P>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request with serializable query parameters.
This method accepts any type implementing Serialize for query parameters,
which are URL-encoded directly into the query string without an intermediate HashMap.
§Errors
Returns an error if unable to send request or times out.
Sourcepub async fn request_with_params_url_redacted<P: Serialize>(
&self,
method: Method,
url: String,
params: Option<&P>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request_with_params_url_redacted<P: Serialize>( &self, method: Method, url: String, params: Option<&P>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request with serializable query parameters while redacting the URL from logs and transport errors.
Use this for query parameters that can carry credentials.
§Errors
Returns an error if unable to send request or times out.
Sourcepub async fn get_stream(
&self,
url: String,
) -> Result<HttpResponseStream, HttpClientError>
pub async fn get_stream( &self, url: String, ) -> Result<HttpResponseStream, HttpClientError>
Sends a GET request and returns its response body as a stream.
Applies default headers and the client timeout. No rate-limit keys are supplied, so no quota is consumed. One absolute deadline covers response headers and the whole body, including time spent processing chunks. Streaming has no total body size limit; callers must process or discard each chunk without accumulating an unbounded body. Dropping the response releases the unfinished exchange, including its simulated driver.
§Errors
Returns an error if request preparation, connection, or response headers fail or time out.
Sourcepub async fn request_with_ustr_keys(
&self,
method: Method,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<Ustr>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn request_with_ustr_keys( &self, method: Method, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<Ustr>>, ) -> Result<HttpResponse, HttpClientError>
Sends an HTTP request using pre-interned rate limiter keys.
§Errors
Returns an error if unable to send the request or the request times out.
Sourcepub async fn get(
&self,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn get( &self, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub async fn post(
&self,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn post( &self, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub async fn patch(
&self,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
body: Option<Vec<u8>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn patch( &self, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, body: Option<Vec<u8>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub async fn delete(
&self,
url: String,
params: Option<&HashMap<String, Vec<String>>>,
headers: Option<HashMap<String, String>>,
timeout_secs: Option<u64>,
keys: Option<Vec<String>>,
) -> Result<HttpResponse, HttpClientError>
pub async fn delete( &self, url: String, params: Option<&HashMap<String, Vec<String>>>, headers: Option<HashMap<String, String>>, timeout_secs: Option<u64>, keys: Option<Vec<String>>, ) -> Result<HttpResponse, HttpClientError>
Sourcepub fn builder() -> HttpClientBuilder
pub fn builder() -> HttpClientBuilder
Returns a builder for a new HttpClient instance.
Set rate_limiters to share quota state across clients. When omitted, the client creates
one rate limiter from default_quota and keyed_quotas. An explicit empty vector disables
rate limiting. Each request awaits every configured limiter with the same keys. A limiter
without a default quota ignores keys it does not own, allowing independent scopes such as
per-IP and per-account limits to apply to one request.
§Errors
Returns an error if:
- Shared rate limiters are combined with quota configuration.
- The proxy URL is malformed.
- Building the underlying HTTP transport fails.
Trait Implementations§
Source§impl Clone for HttpClient
impl Clone for HttpClient
Source§fn clone(&self) -> HttpClient
fn clone(&self) -> HttpClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more