pub trait HttpClient: Send + Sync {
// Required method
fn send<'a>(
&'a self,
request: &'a HttpRequest,
control: HttpControl,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'a>>;
// Provided methods
fn get_text<'a>(
&'a self,
url: &'a str,
) -> Pin<Box<dyn Future<Output = Result<String, HttpError>> + Send + 'a>> { ... }
fn get_bytes<'a>(
&'a self,
url: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HttpError>> + Send + 'a>> { ... }
fn download_to<'a>(
&'a self,
url: &'a str,
target: &'a Path,
control: HttpControl,
) -> Pin<Box<dyn Future<Output = Result<u64, HttpError>> + Send + 'a>> { ... }
}Expand description
A platform’s HTTP.
One method carries the whole contract: everything else — text, bytes, a file
on disk — is that method plus what the caller does with the body, so a
backend implements the transfer once and cannot make get_text behave
differently from download_to.
Required Methods§
Sourcefn send<'a>(
&'a self,
request: &'a HttpRequest,
control: HttpControl,
) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'a>>
fn send<'a>( &'a self, request: &'a HttpRequest, control: HttpControl, ) -> Pin<Box<dyn Future<Output = Result<HttpResponse, HttpError>> + Send + 'a>>
Sends request, resolving when the response’s status line has arrived
and its body is ready to be read.
Provided Methods§
Sourcefn get_text<'a>(
&'a self,
url: &'a str,
) -> Pin<Box<dyn Future<Output = Result<String, HttpError>> + Send + 'a>>
fn get_text<'a>( &'a self, url: &'a str, ) -> Pin<Box<dyn Future<Output = Result<String, HttpError>> + Send + 'a>>
The body of a successful GET, as text.
Sourcefn get_bytes<'a>(
&'a self,
url: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HttpError>> + Send + 'a>>
fn get_bytes<'a>( &'a self, url: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HttpError>> + Send + 'a>>
The body of a successful GET.
Sourcefn download_to<'a>(
&'a self,
url: &'a str,
target: &'a Path,
control: HttpControl,
) -> Pin<Box<dyn Future<Output = Result<u64, HttpError>> + Send + 'a>>
fn download_to<'a>( &'a self, url: &'a str, target: &'a Path, control: HttpControl, ) -> Pin<Box<dyn Future<Output = Result<u64, HttpError>> + Send + 'a>>
Streams a response into target, resuming from its current length when
the server supports byte ranges, and returns the file’s whole length.
This is the appropriate call for model packs and other files that should not be held in memory. A cancelled transfer leaves the partial file where it is, which is what lets the next attempt continue rather than start again.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".