[−][src]Struct reqwest::ClientBuilder
A ClientBuilder can be used to create a Client with custom configuration.
Example
use std::time::Duration; let client = reqwest::Client::builder() .gzip(true) .timeout(Duration::from_secs(10)) .build()?;
Methods
impl ClientBuilder[src]
impl ClientBuilderpub fn new() -> ClientBuilder[src]
pub fn new() -> ClientBuilderConstructs a new ClientBuilder
pub fn build(self) -> Result<Client>[src]
pub fn build(self) -> Result<Client>Returns a Client that uses this ClientBuilder configuration.
Errors
This method fails if native TLS backend cannot be initialized.
pub fn add_root_certificate(self, cert: Certificate) -> ClientBuilder[src]
pub fn add_root_certificate(self, cert: Certificate) -> ClientBuilderAdd a custom root certificate.
This can be used to connect to a server that has a self-signed certificate for example.
Example
// read a local binary DER encoded certificate let mut buf = Vec::new(); File::open("my-cert.der")?.read_to_end(&mut buf)?; // create a certificate let cert = reqwest::Certificate::from_der(&buf)?; // get a client builder let client = reqwest::Client::builder() .add_root_certificate(cert) .build()?;
Errors
This method fails if adding root certificate was unsuccessful.
pub fn identity(self, identity: Identity) -> ClientBuilder[src]
pub fn identity(self, identity: Identity) -> ClientBuilderSets the identity to be used for client certificate authentication.
Example
// read a local PKCS12 bundle let mut buf = Vec::new(); File::open("my-ident.pfx")?.read_to_end(&mut buf)?; // create an Identity from the PKCS#12 archive let pkcs12 = reqwest::Identity::from_pkcs12_der(&buf, "my-privkey-password")?; // get a client builder let client = reqwest::Client::builder() .identity(pkcs12) .build()?;
pub fn danger_accept_invalid_hostnames(
self,
accept_invalid_hostname: bool
) -> ClientBuilder[src]
pub fn danger_accept_invalid_hostnames(
self,
accept_invalid_hostname: bool
) -> ClientBuilderControls the use of hostname verification.
Defaults to false.
Warning
You should think very carefully before you use this method. If hostname verification is not used, any valid certificate for any site will be trusted for use from any other. This introduces a significant vulnerability to man-in-the-middle attacks.
pub fn danger_accept_invalid_certs(
self,
accept_invalid_certs: bool
) -> ClientBuilder[src]
pub fn danger_accept_invalid_certs(
self,
accept_invalid_certs: bool
) -> ClientBuilderControls the use of certificate validation.
Defaults to false.
Warning
You should think very carefully before using this method. If invalid certificates are trusted, any certificate for any site will be trusted for use. This includes expired certificates. This introduces significant vulnerabilities, and should only be used as a last resort.
pub fn default_headers(self, headers: HeaderMap) -> ClientBuilder[src]
pub fn default_headers(self, headers: HeaderMap) -> ClientBuilderSets the default headers for every request.
Example
use reqwest::header; let mut headers = header::HeaderMap::new(); headers.insert(header::AUTHORIZATION, header::HeaderValue::from_static("secret")); // get a client builder let client = reqwest::Client::builder() .default_headers(headers) .build()?; let res = client.get("https://www.rust-lang.org").send()?;
Override the default headers:
use reqwest::header; let mut headers = header::HeaderMap::new(); headers.insert(header::AUTHORIZATION, header::HeaderValue::from_static("secret")); // get a client builder let client = reqwest::Client::builder() .default_headers(headers) .build()?; let res = client .get("https://www.rust-lang.org") .header(header::AUTHORIZATION, "token") .send()?;
pub fn gzip(self, enable: bool) -> ClientBuilder[src]
pub fn gzip(self, enable: bool) -> ClientBuilderEnable auto gzip decompression by checking the ContentEncoding response header.
If auto gzip decompresson is turned on:
- When sending a request and if the request's headers do not already contain
an
Accept-EncodingandRangevalues, theAccept-Encodingheader is set togzip. The body is not automatically inflated. - When receiving a response, if it's headers contain a
Content-Encodingvalue that equals togzip, both valuesContent-EncodingandContent-Lengthare removed from the headers' set. The body is automatically deinflated.
Default is enabled.
pub fn proxy(self, proxy: Proxy) -> ClientBuilder[src]
pub fn proxy(self, proxy: Proxy) -> ClientBuilderAdd a Proxy to the list of proxies the Client will use.
pub fn redirect(self, policy: RedirectPolicy) -> ClientBuilder[src]
pub fn redirect(self, policy: RedirectPolicy) -> ClientBuilderSet a RedirectPolicy for this client.
Default will follow redirects up to a maximum of 10.
pub fn referer(self, enable: bool) -> ClientBuilder[src]
pub fn referer(self, enable: bool) -> ClientBuilderEnable or disable automatic setting of the Referer header.
Default is true.
pub fn timeout<T>(self, timeout: T) -> ClientBuilder where
T: Into<Option<Duration>>, [src]
pub fn timeout<T>(self, timeout: T) -> ClientBuilder where
T: Into<Option<Duration>>, Set a timeout for connect, read and write operations of a Client.
Default is 30 seconds.
Pass None to disable timeout.
Trait Implementations
impl Debug for ClientBuilder[src]
impl Debug for ClientBuilderAuto Trait Implementations
impl Send for ClientBuilder
impl Send for ClientBuilderimpl Sync for ClientBuilder
impl Sync for ClientBuilderBlanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>try_from)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut TMutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>try_from)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeId🔬 This is a nightly-only experimental API. (get_type_id)
this method will likely be replaced by an associated static
Gets the TypeId of self. Read more
impl<T> Erased for T[src]
impl<T> Erased for T