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: u32the longest wait for any read or write
deadline_ms: u32the 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: u8redirects followed at most (0: a 3xx answer comes back as it is)
decode: booloffer gzip and br and decode the body (see the module header)
Implementations§
Source§impl Client
impl Client
pub fn new() -> Client
Sourcepub fn with_connector(self, c: Connector) -> Client
pub fn with_connector(self, c: Connector) -> Client
the TLS layer for https URLs
Sourcepub fn with_proxy(self, p: Proxy) -> Client
pub fn with_proxy(self, p: Proxy) -> Client
requests go through these proxies (netio::proxy)
Sourcepub fn with_pool(self, p: Arc<Pool>) -> Client
pub fn with_pool(self, p: Arc<Pool>) -> Client
connections stay open for the next requests (keep-alive); clones of the client share them
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)
Sourcepub fn with_redirects(self, n: u8) -> Client
pub fn with_redirects(self, n: u8) -> Client
redirects: followed up to n (0: none)
Sourcepub fn with_redirect_check(self, f: RedirectCheck) -> Client
pub fn with_redirect_check(self, f: RedirectCheck) -> Client
each redirect first asks f(from, to); false: the 3xx answer is the result
the jar given to with_cookies
Sourcepub fn connect(&self, url: &Url) -> Result<Box<dyn Stream>, HttpError>
pub fn connect(&self, url: &Url) -> Result<Box<dyn Stream>, HttpError>
open the connection a request to url goes over, directly (no proxy)
Sourcepub fn request(
&self,
method: &str,
url: &Url,
headers: &Headers,
body: &[u8],
) -> Result<Response, HttpError>
pub fn request( &self, method: &str, url: &Url, headers: &Headers, body: &[u8], ) -> Result<Response, HttpError>
send one request and read the whole answer
Sourcepub fn fetch(
&self,
method: &str,
url: &Url,
headers: &Headers,
body: &[u8],
) -> Result<Fetched, HttpError>
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)
Sourcepub fn request_on(
&self,
s: &dyn Stream,
method: &str,
url: &Url,
headers: &Headers,
body: &[u8],
) -> Result<Response, HttpError>
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)
Sourcepub fn get_to(
&self,
url: &Url,
headers: &Headers,
max: u64,
on: &mut dyn FnMut(Part<'_>) -> bool,
) -> Result<(u16, Headers), HttpError>
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
pub fn get(&self, url: &Url, headers: &Headers) -> Result<Response, HttpError>
Sourcepub fn request_async(
&self,
method: &str,
url: &Url,
headers: &Headers,
body: Vec<u8>,
) -> impl Future<Output = Result<Response, HttpError>> + use<>
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
Sourcepub fn download(
&self,
url: &Url,
headers: &Headers,
path: &str,
ctl: &Ctl,
) -> impl Future<Output = Result<u16, HttpError>> + use<>
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