pub struct Client { /* private fields */ }Expand description
Defaults shared by several requests: headers, timeouts and redirect handling. Requests built from a client start with these values and can override each of them.
use std::time::Duration;
use curlite::{HeaderValue, header::AUTHORIZATION};
let api = curlite::Client::new()
.header(AUTHORIZATION, HeaderValue::from_static("Bearer secret"))
.timeout(Duration::from_secs(5));
let me = api.get("https://example.com/me").send()?;
let them = api.get("https://example.com/them").send()?;A client holds configuration only. The libcurl handle, and with it the
connection cache, belongs to the thread; see Request::send.
Implementations§
Source§impl Client
impl Client
Sourcepub fn header(self, name: HeaderName, value: HeaderValue) -> Self
pub fn header(self, name: HeaderName, value: HeaderValue) -> Self
A header sent with every request, unless the request sets the same
name itself. Takes parsed types so that building a client cannot
fail; Request::header accepts strings.
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
See Request::timeout.
Sourcepub fn connect_timeout(self, timeout: Duration) -> Self
pub fn connect_timeout(self, timeout: Duration) -> Self
Sourcepub fn stall_timeout(self, timeout: Duration) -> Self
pub fn stall_timeout(self, timeout: Duration) -> Self
Sourcepub fn follow_redirects(self, follow: bool) -> Self
pub fn follow_redirects(self, follow: bool) -> Self
Sourcepub fn max_redirects(self, max: u32) -> Self
pub fn max_redirects(self, max: u32) -> Self
Sourcepub fn http_version(self, version: HttpVersion) -> Self
pub fn http_version(self, version: HttpVersion) -> Self
Sourcepub fn proxy(self, proxy: impl Into<String>) -> Self
pub fn proxy(self, proxy: impl Into<String>) -> Self
See Request::proxy.
Sourcepub fn unix_socket(self, path: impl Into<PathBuf>) -> Self
pub fn unix_socket(self, path: impl Into<PathBuf>) -> Self
See Request::unix_socket.
Sourcepub fn ca_bundle(self, path: impl Into<PathBuf>) -> Self
pub fn ca_bundle(self, path: impl Into<PathBuf>) -> Self
See Request::ca_bundle.
Sourcepub fn danger_accept_invalid_certs(self) -> Self
pub fn danger_accept_invalid_certs(self) -> Self
Sourcepub fn compression(self, enabled: bool) -> Self
pub fn compression(self, enabled: bool) -> Self
See Request::compression.
Sourcepub fn auth(self, auth: Auth) -> Self
pub fn auth(self, auth: Auth) -> Self
See Request::auth.
Sourcepub fn basic_auth(
self,
user: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn basic_auth( self, user: impl Into<String>, password: impl Into<String>, ) -> Self
See Request::basic_auth.
Sourcepub fn bearer_auth(self, token: impl Into<String>) -> Self
pub fn bearer_auth(self, token: impl Into<String>) -> Self
See Request::bearer_auth.
Sourcepub fn netrc(self) -> Self
pub fn netrc(self) -> Self
See Request::netrc.
Sourcepub fn proxy_auth(self, auth: Auth) -> Self
pub fn proxy_auth(self, auth: Auth) -> Self
See Request::proxy_auth.
Sourcepub fn client_cert(
self,
cert: impl Into<PathBuf>,
key: impl Into<PathBuf>,
) -> Self
pub fn client_cert( self, cert: impl Into<PathBuf>, key: impl Into<PathBuf>, ) -> Self
See Request::client_cert.
Sourcepub fn max_body_size(self, limit: Option<u64>) -> Self
pub fn max_body_size(self, limit: Option<u64>) -> Self
Sourcepub fn request(&self, method: Method, url: &str) -> Request
pub fn request(&self, method: Method, url: &str) -> Request
Starts a request with this client’s defaults.