Skip to main content

HttpClient

Struct HttpClient 

Source
pub struct HttpClient { /* private fields */ }
Expand description

A pooled HTTP client; see the module documentation.

Implementations§

Source§

impl HttpClient

Source

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).

Source

pub const fn implementation(&self) -> HttpImpl

The implementation in use.

Source

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.

Source

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.

Source

pub fn idle(&self) -> usize

Requests that can be sent now without Error::Busy: idle open connections (native) or free handles (libcurl).

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.