pub struct HttpClient { /* private fields */ }Expand description
A pooled HTTP client; see the module documentation.
Implementations§
Source§impl HttpClient
impl HttpClient
Sourcepub fn new(
cfg: &HttpClientConfig,
target: Target,
tls: Arc<ClientConfig>,
) -> Result<Self>
pub fn new( cfg: &HttpClientConfig, target: Target, tls: Arc<ClientConfig>, ) -> Result<Self>
A client for target (its headers, such as the API key, go with every
request). Native connections start opening at once (with
HttpClientConfig::connect_gate, from the first poll_gated); a
connection that cannot be opened is reported to
ClientHandler::on_connect_error from poll and retried.
§Errors
The implementation is not built in, the configuration is invalid
(headers, TLS config, connect_gate with libcurl), or the driver or
libcurl fails to initialise. Error::Cpu: background connects
with no CPU for the connect helper (see
HttpClientConfig::background_connect).
Sourcepub const fn implementation(&self) -> HttpImpl
pub const fn implementation(&self) -> HttpImpl
The implementation in use.
Sourcepub fn connect_failures(&self) -> u64
pub fn connect_failures(&self) -> u64
Connections the native pool failed to open since it was created (each
also went to ClientHandler::on_connect_error); 0 for libcurl, which
reports connect failures as request errors.
Sourcepub fn route_checks(&self) -> Vec<RouteCheck>
pub fn route_checks(&self) -> Vec<RouteCheck>
What the quick-ACK route check (driver.quickack_check, see
crate::route) found for each connection: the pool’s open
connections (native), or the connection each libcurl handle last
used. Allocates: for diagnostics, not the request path.
Sourcepub fn idle(&self) -> usize
pub fn idle(&self) -> usize
Requests that can be sent now without Error::Busy: idle open
connections (native) or free handles (libcurl).
Sourcepub fn request(
&mut self,
method: &str,
path: &str,
headers: &[(&str, &str)],
body: &[u8],
) -> Result<u64>
pub fn request( &mut self, method: &str, path: &str, headers: &[(&str, &str)], body: &[u8], ) -> Result<u64>
Sends a request (path may carry a query). Returns its id.
§Errors
Error::Busy when no connection or handle is free, or an invalid
request.
Sourcepub fn signed_request(
&mut self,
method: &str,
path: &str,
params: &str,
headers: &[(&str, &str)],
signer: &Signer,
) -> Result<u64>
pub fn signed_request( &mut self, method: &str, path: &str, params: &str, headers: &[(&str, &str)], signer: &Signer, ) -> Result<u64>
Sends a signed request: params, timestamp (this host’s UTC, ms)
and signature in the query string, as HttpConn::signed_request.
Returns its id.
§Errors
As HttpClient::request, or params needs percent-encoding.
Sourcepub fn signed_request_at(
&mut self,
method: &str,
path: &str,
params: &str,
headers: &[(&str, &str)],
signer: &Signer,
timestamp_ms: u64,
) -> Result<u64>
pub fn signed_request_at( &mut self, method: &str, path: &str, params: &str, headers: &[(&str, &str)], signer: &Signer, timestamp_ms: u64, ) -> Result<u64>
HttpClient::signed_request with the caller’s timestamp, in ms
since 1970: a clock of the caller’s choice, or replay time.
§Errors
As HttpClient::signed_request, or path has a query (put it in
params).
Sourcepub fn poll<H: ClientHandler>(&mut self, handler: &mut H) -> Result<usize>
pub fn poll<H: ClientHandler>(&mut self, handler: &mut H) -> Result<usize>
One non-blocking iteration: moves bytes, reports finished requests, and replaces dropped connections. Returns requests finished.
§Errors
The driver or libcurl failed as a whole (per-request failures go to
ClientHandler::on_error). Error::Config for a pool with
HttpClientConfig::connect_gate: use HttpClient::poll_gated.
Sourcepub fn poll_gated<H: ClientHandler>(&mut self, handler: &mut H) -> Result<usize>
pub fn poll_gated<H: ClientHandler>(&mut self, handler: &mut H) -> Result<usize>
HttpClient::poll, but a pool connect starts only when
ClientHandler::connect_gate passes it: a venue’s limit on
connects per IP. The gate is the handler’s, so it can share the
handler’s Budget (see ClientHandler::connect_gate).
§Errors
As HttpClient::poll; Error::Unsupported for libcurl, which
opens its own connections.