pub struct Client { /* private fields */ }Expand description
The guarded client. Cheap to clone; clones share a connection pool.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(config: ClientConfig) -> Result<Self, RequestError>
pub fn new(config: ClientConfig) -> Result<Self, RequestError>
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
The configuration the client was built with.
Sourcepub async fn get(
&self,
url: &Url,
headers: HeaderMap,
) -> Result<Response, RequestError>
pub async fn get( &self, url: &Url, headers: HeaderMap, ) -> Result<Response, RequestError>
GET url, following redirects.
§Errors
When the URL or an address is refused, the response is too large, or
the request fails. A response with any status is Ok.
Sourcepub async fn get_direct(
&self,
url: &Url,
headers: HeaderMap,
) -> Result<Response, RequestError>
pub async fn get_direct( &self, url: &Url, headers: HeaderMap, ) -> Result<Response, RequestError>
Sourcepub async fn post(
&self,
url: &Url,
headers: HeaderMap,
body: Vec<u8>,
) -> Result<Response, RequestError>
pub async fn post( &self, url: &Url, headers: HeaderMap, body: Vec<u8>, ) -> Result<Response, RequestError>
Sourcepub fn request(
&self,
method: Method,
url: &Url,
) -> Result<RequestBuilder, RequestError>
pub fn request( &self, method: Method, url: &Url, ) -> Result<RequestBuilder, RequestError>
A request to url, following redirects, for the application to add
to, send and read itself: a GET of something that is not a document,
such as a link’s preview or a media file, whose body may be large and
is better read as a stream than all at once.
The request goes through the same guard as every other, url here
and each address and redirect when it is sent, with the client’s
connect and overall timeouts, either of which the builder may
shorten. Nothing bounds the body but how the caller reads it:
ClientConfig::max_response_bytes applies only to what the client
reads in full. An error from sending it converts into a
RequestError, a refusal included.
§Errors
When url is refused, as validate_url.