Trait HttpClient

Source
pub trait HttpClient:
    Debug
    + Unpin
    + Send
    + Sync
    + 'static {
    // Required method
    fn send<'life0, 'async_trait>(
        &'life0 self,
        req: Request,
    ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn set_config(&mut self, _config: Config) -> Result<()> { ... }
    fn config(&self) -> &Config { ... }
}
Expand description

An abstract HTTP client.

note that this is only exposed for use in middleware. Building new backing clients is not recommended yet. Once it is we’ll likely publish a new http_client crate, and re-export this trait from there together with all existing HTTP client implementations.

§Spawning new request from middleware

When threading the trait through a layer of middleware, the middleware must be able to perform new requests. In order to enable this efficiently an HttpClient instance may want to be passed though middleware for one of its own requests, and in order to do so should be wrapped in an Rc/Arc to enable reference cloning.

Required Methods§

Source

fn send<'life0, 'async_trait>( &'life0 self, req: Request, ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Perform a request.

Provided Methods§

Source

fn set_config(&mut self, _config: Config) -> Result<()>

Override the existing configuration with new configuration.

Config options may not impact existing connections.

Source

fn config(&self) -> &Config

Get the current configuration.

Trait Implementations§

Source§

impl HttpClient for Box<dyn HttpClient>

Source§

fn send<'life0, 'async_trait>( &'life0 self, req: Request, ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Perform a request.
Source§

fn set_config(&mut self, config: Config) -> Result<()>

Override the existing configuration with new configuration. Read more
Source§

fn config(&self) -> &Config

Get the current configuration.

Implementations on Foreign Types§

Source§

impl HttpClient for Box<dyn HttpClient>

Source§

fn send<'life0, 'async_trait>( &'life0 self, req: Request, ) -> Pin<Box<dyn Future<Output = Result<Response>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn set_config(&mut self, config: Config) -> Result<()>

Source§

fn config(&self) -> &Config

Implementors§

Source§

impl HttpClient for H1Client

Available on crate features h1_client and default only.
Source§

impl HttpClient for HyperClient

Available on crate feature hyper_client only.
Source§

impl HttpClient for IsahcClient

Available on crate feature curl_client only.