Skip to main content

Client

Struct Client 

Source
pub struct Client {
    pub connect_ms: u32,
    pub timeout_ms: u32,
    pub deadline_ms: u32,
    pub max_body: usize,
    pub user_agent: String,
    pub redirects: u8,
    pub decode: bool,
    /* private fields */
}

Fields§

§connect_ms: u32§timeout_ms: u32

the longest wait for any read or write

§deadline_ms: u32

the longest a whole request may take, from connecting to the last byte of the body, redirects and retries included; what it bounds and what not: the module header (0: no limit beyond timeout_ms per read)

§max_body: usize§user_agent: String§redirects: u8

redirects followed at most (0: a 3xx answer comes back as it is)

§decode: bool

offer gzip and br and decode the body (see the module header)

Implementations§

Source§

impl Client

Source

pub fn new() -> Client

Source

pub fn with_connector(self, c: Connector) -> Client

the TLS layer for https URLs

Source

pub fn with_proxy(self, p: Proxy) -> Client

requests go through these proxies (netio::proxy)

Source

pub fn with_pool(self, p: Arc<Pool>) -> Client

connections stay open for the next requests (keep-alive); clones of the client share them

Source

pub fn with_cookies(self, jar: Arc<Mutex<Jar>>) -> Client

cookies: what answers set is stored in the jar, a request without a Cookie header of the caller’s sends the jar’s for its URL (netpkt::cookie, with the public suffix list)

Source

pub fn with_redirects(self, n: u8) -> Client

redirects: followed up to n (0: none)

Source

pub fn with_redirect_check(self, f: RedirectCheck) -> Client

each redirect first asks f(from, to); false: the 3xx answer is the result

Source

pub fn cookies(&self) -> Option<&Arc<Mutex<Jar>>>

the jar given to with_cookies

Source

pub fn connect(&self, url: &Url) -> Result<Box<dyn Stream>, HttpError>

open the connection a request to url goes over, directly (no proxy)

Source

pub fn request( &self, method: &str, url: &Url, headers: &Headers, body: &[u8], ) -> Result<Response, HttpError>

send one request and read the whole answer

Source

pub fn fetch( &self, method: &str, url: &Url, headers: &Headers, body: &[u8], ) -> Result<Fetched, HttpError>

request(), and the URL the answer came from (after redirects)

Source

pub fn request_on( &self, s: &dyn Stream, method: &str, url: &Url, headers: &Headers, body: &[u8], ) -> Result<Response, HttpError>

One request over a connection the caller opened (a socket of its own, a test’s stream): the client’s headers, cookies and decoding, no proxy, pool or redirects; the request asks to close the connection, and the stream stays open (with deadline_ms, its timeouts are the time left as the request goes)

Source

pub fn get_to( &self, url: &Url, headers: &Headers, max: u64, on: &mut dyn FnMut(Part<'_>) -> bool, ) -> Result<(u16, Headers), HttpError>

a GET whose answer goes piece by piece to on (downloads larger than memory): first Part::Head (false: skip the body), then Part::Data for every piece of the body (false: stop, Err(HttpError::Bad)). The body may have up to max bytes. Redirects the client follows do not reach on. -> the status and the headers

Source

pub fn get(&self, url: &Url, headers: &Headers) -> Result<Response, HttpError>

Source

pub fn request_async( &self, method: &str, url: &Url, headers: &Headers, body: Vec<u8>, ) -> impl Future<Output = Result<Response, HttpError>> + use<>

request() on the blocking pool (plat::task::spawn_blocking): a future of the answer

Source

pub fn download( &self, url: &Url, headers: &Headers, path: &str, ctl: &Ctl, ) -> impl Future<Output = Result<u16, HttpError>> + use<>

A GET whose body goes into the file at path, on the blocking pool. The file is replaced like plat::write_file (plat::AtomicFile) and only by the whole body of a 2xx answer; other answers leave it alone. ctl.progress counts the bytes (the total from Content-Length); ctl.cancel, or dropping the future, stops between pieces: Err(Cancelled), the file unchanged. -> the status

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 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
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<dyn Fn(&Url, TcpStream) -> Result<Box<dyn Stream>, HttpError> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&Url, TcpStream) -> Result<Box<dyn Stream>, HttpError> + Sync + Send>>: Freeze, PhantomData<NoProxy>: Freeze, *const ArcInner<Pool> is !null: Freeze, PhantomData<ArcInner<Pool>>: Freeze, *const ArcInner<Mutex<Jar>> is !null: Freeze, PhantomData<ArcInner<Mutex<Jar>>>: Freeze, *const ArcInner<dyn Fn(&Url, &Url) -> bool + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn Fn(&Url, &Url) -> bool + Sync + Send>>: Freeze,

§

impl Move for Client

§

impl Send for Client
where RawVecInner: Send, Arc<dyn Fn(&Url, TcpStream) -> Result<Box<dyn Stream>, HttpError> + Sync + Send>: Send, Arc<Pool>: Send, Arc<Mutex<Jar>>: Send, Arc<dyn Fn(&Url, &Url) -> bool + Sync + Send>: Send,

§

impl Sync for Client
where RawVecInner: Sync, Arc<dyn Fn(&Url, TcpStream) -> Result<Box<dyn Stream>, HttpError> + Sync + Send>: Sync, Arc<Pool>: Sync, Arc<Mutex<Jar>>: Sync, Arc<dyn Fn(&Url, &Url) -> bool + Sync + Send>: Sync,

§

impl Unpin for Client
where *const u8 is !null: Unpin, Arc<dyn Fn(&Url, TcpStream) -> Result<Box<dyn Stream>, HttpError> + Sync + Send>: Unpin, Arc<Pool>: Unpin, Arc<Mutex<Jar>>: Unpin, Arc<dyn Fn(&Url, &Url) -> bool + Sync + Send>: Unpin,

§

impl UnsafeUnpin for Client
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<dyn Fn(&Url, TcpStream) -> Result<Box<dyn Stream>, HttpError> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&Url, TcpStream) -> Result<Box<dyn Stream>, HttpError> + Sync + Send>>: UnsafeUnpin, PhantomData<NoProxy>: UnsafeUnpin, *const ArcInner<Pool> is !null: UnsafeUnpin, PhantomData<ArcInner<Pool>>: UnsafeUnpin, *const ArcInner<Mutex<Jar>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Jar>>>: UnsafeUnpin, *const ArcInner<dyn Fn(&Url, &Url) -> bool + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn Fn(&Url, &Url) -> bool + Sync + Send>>: UnsafeUnpin,

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> 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.