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.
Request URLs in transport errors and response-stream diagnostics are limited to their origin
(scheme, host, and port). Userinfo, paths, queries, and fragments are excluded. Set
redact_url(true) on the builder to omit the origin too. This policy does not change requests
or diagnostic messages from lower layers. It controls the URL context added by this client.
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_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 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.
NAUTILUS_HTTP2_ADAPTIVE_WINDOWis set to a value other thantrueorfalse.- Building the underlying HTTP transport fails.