Skip to main content

Client

Struct Client 

Source
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

Source

pub fn new() -> Client

A client with the default policy over the platform’s transport.

Source

pub fn builder() -> ClientBuilder

Configure a client.

Source

pub fn capabilities(&self) -> Capabilities

What this client’s transport can do.

Source

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.

Source

pub fn send_future(&self, request: Request) -> Sending ⓘ

Send request and await the response head. Dropping the future cancels the request.

Source

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.

Source

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.

Source

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.

Source

pub fn fetch_future(&self, request: Request) -> Fetching ⓘ

Send request and await the whole response. Dropping the future cancels the request.

Source

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.

Source

pub fn websocket_future(&self, request: Request) -> Connecting ⓘ

Open a WebSocket and await the handshake. Dropping the future abandons the connection.

Source

pub fn cookies(&self) -> Vec<Cookie>

The cookies this client would send, from its jar or the platform’s store.

Source

pub fn clear_cookies(&self)

Forget every cookie in this client’s jar or the platform’s store.

Source

pub fn clear_cache(&self)

Empty the platform cache this client uses.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Client

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl !UnwindSafe for Client

§

impl Forget for Client

§

impl Freeze for Client

§

impl Move for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl UnsafeUnpin for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.