pub trait HttpClient: Send + Sync {
// Required method
fn send<'a>(
&'a self,
request: &'a HttpRequest,
control: HttpControl,
) -> HttpFuture<'a, HttpResponse>;
// Provided methods
fn get_text<'a>(&'a self, url: &'a str) -> HttpFuture<'a, String> { ... }
fn get_bytes<'a>(&'a self, url: &'a str) -> HttpFuture<'a, Vec<u8>> { ... }
fn download_to<'a>(
&'a self,
url: &'a str,
target: &'a Path,
control: HttpControl,
) -> HttpFuture<'a, u64> { ... }
}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,
) -> HttpFuture<'a, HttpResponse>
fn send<'a>( &'a self, request: &'a HttpRequest, control: HttpControl, ) -> HttpFuture<'a, HttpResponse>
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) -> HttpFuture<'a, String>
fn get_text<'a>(&'a self, url: &'a str) -> HttpFuture<'a, String>
The body of a successful GET, as text.
Sourcefn get_bytes<'a>(&'a self, url: &'a str) -> HttpFuture<'a, Vec<u8>>
fn get_bytes<'a>(&'a self, url: &'a str) -> HttpFuture<'a, Vec<u8>>
The body of a successful GET.
Sourcefn download_to<'a>(
&'a self,
url: &'a str,
target: &'a Path,
control: HttpControl,
) -> HttpFuture<'a, u64>
fn download_to<'a>( &'a self, url: &'a str, target: &'a Path, control: HttpControl, ) -> HttpFuture<'a, u64>
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".