pub struct Client { /* private fields */ }Expand description
An HTTP client: policy shared by every request it sends, over the platform’s transport. Cloning is cheap and shares the policy, the cookies and the connections.
Implementations§
Source§impl Client
impl Client
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Configure a client.
Sourcepub fn capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
What this client’s transport can do.
Sourcepub fn send_async(
&self,
request: Request,
on_head: impl FnOnce(Result<Streaming, HttpError>) + Send + 'static,
) -> InFlight
pub fn send_async( &self, request: Request, on_head: impl FnOnce(Result<Streaming, HttpError>) + Send + 'static, ) -> InFlight
Send request; on_head receives the response head with its unread Body, or the
failure. It runs on the thread the platform reports on.
Sourcepub fn send_future(&self, request: Request) -> Sending ⓘ
pub fn send_future(&self, request: Request) -> Sending ⓘ
Send request and await the response head. Dropping the future cancels the request.
Sourcepub async fn fetch_limited_future(
&self,
request: Request,
max_bytes: usize,
) -> Result<Response, HttpError>
pub async fn fetch_limited_future( &self, request: Request, max_bytes: usize, ) -> Result<Response, HttpError>
Buffer at most max_bytes, cancelling if either Content-Length or the actual streamed
body exceeds it. The bound applies to decoded response bytes delivered by the transport.
§Errors
HttpError::BodyTooLarge when the advertised or received body exceeds max_bytes, and
otherwise the HttpError the request or its body stream fails with.
Sourcepub async fn fetch_limited_with_progress_future(
&self,
request: Request,
max_bytes: usize,
progress: impl FnMut(u64, Option<u64>),
) -> Result<Response, HttpError>
pub async fn fetch_limited_with_progress_future( &self, request: Request, max_bytes: usize, progress: impl FnMut(u64, Option<u64>), ) -> Result<Response, HttpError>
Bounded download with (received, total) observations on the polling thread.
Unknown or encoded representation lengths report None, never a guessed fraction.
Observer calls occur at connection start, response headers, and each body chunk;
UI consumers should throttle their presentation updates.
§Errors
HttpError::BodyTooLarge when the advertised or received body exceeds max_bytes, and
otherwise the HttpError the request or its body stream fails with.
Sourcepub fn fetch_async(
&self,
request: Request,
on_done: impl FnOnce(Result<Response, HttpError>) + Send + 'static,
) -> InFlight
pub fn fetch_async( &self, request: Request, on_done: impl FnOnce(Result<Response, HttpError>) + Send + 'static, ) -> InFlight
Send request and read its whole body into memory. For large bodies use
Client::send_async and read the Body in chunks.
Sourcepub fn fetch_future(&self, request: Request) -> Fetching ⓘ
pub fn fetch_future(&self, request: Request) -> Fetching ⓘ
Send request and await the whole response. Dropping the future cancels the request.
Sourcepub fn websocket_async(
&self,
request: Request,
on_open: impl FnOnce(Result<WebSocket, HttpError>) + Send + 'static,
)
pub fn websocket_async( &self, request: Request, on_open: impl FnOnce(Result<WebSocket, HttpError>) + Send + 'static, )
Open a WebSocket (ws:// or wss://); on_open receives it after the handshake, or the
failure.
Sourcepub fn websocket_future(&self, request: Request) -> Connecting ⓘ
pub fn websocket_future(&self, request: Request) -> Connecting ⓘ
Open a WebSocket and await the handshake. Dropping the future abandons the connection.
The cookies this client would send, from its jar or the platform’s store.
Forget every cookie in this client’s jar or the platform’s store.
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Empty the platform cache this client uses.