Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient {
    // Required methods
    fn run<C, T, E>(&mut self, coroutine: C) -> Result<T, HttpClientError>
       where C: HttpCoroutine<Yield = HttpYield, Return = Result<T, E>>,
             HttpClientError: From<E>;
    fn run_send<C, E>(
        &mut self,
        coroutine: C,
    ) -> Result<HttpSendOutput, HttpClientError>
       where C: HttpCoroutine<Yield = HttpSendYield, Return = Result<HttpSendOutput, E>>,
             HttpClientError: From<E>;

    // Provided methods
    fn send(
        &mut self,
        request: HttpRequest,
    ) -> Result<HttpSendOutput, HttpClientError> { ... }
    fn send_http10(
        &mut self,
        request: HttpRequest,
    ) -> Result<HttpSendOutput, HttpClientError> { ... }
}
Available on crate feature client only.
Expand description

Blocking HTTP request surface: implement the two pumps and inherit the commands.

HttpClientStd implements it over a Read + Write stream; a caller whose transport is its own (a JNI upcall bridge, an in-memory test double) implements the same two methods and gets the rest.

There are two pumps rather than one because HTTP has two yield vocabularies. run takes the plain read/write coroutines, the ones every client wraps identically. run_send takes the request coroutines, which also yield HttpSendYield::WantsRedirect, and that yield is a policy question: this crate’s own client refuses a redirect, a browser-shaped one would follow it, and a consumer bounded by an allow-list would inspect it. Making it a required method puts the decision in the implementor’s hands and keeps it out of the defaults.

The trait is not dyn-compatible, because both pumps are generic. The dynamism this crate needs lives one layer down, at the boxed stream HttpClientStd holds.

Required Methods§

Source

fn run<C, T, E>(&mut self, coroutine: C) -> Result<T, HttpClientError>
where C: HttpCoroutine<Yield = HttpYield, Return = Result<T, E>>, HttpClientError: From<E>,

Runs a standard-shape coroutine to completion, fulfilling its read and write requests against the transport.

Source

fn run_send<C, E>( &mut self, coroutine: C, ) -> Result<HttpSendOutput, HttpClientError>

Runs a request coroutine to completion, deciding what a redirect means along the way.

Provided Methods§

Source

fn send( &mut self, request: HttpRequest, ) -> Result<HttpSendOutput, HttpClientError>

Sends one HTTP/1.1 request and reads its response.

Source

fn send_http10( &mut self, request: HttpRequest, ) -> Result<HttpSendOutput, HttpClientError>

HTTP/1.0 counterpart of send.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§