[−][src]Struct reqwest::ClientBuilder
pub struct ClientBuilder { /* fields omitted */ }
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 ClientBuilder
pub fn new() -> ClientBuilder
[src]
pub fn new() -> ClientBuilder
Constructs a new ClientBuilder
pub fn build(&mut self) -> Result<Client>
[src]
pub fn build(&mut self) -> Result<Client>
Returns a Client
that uses this ClientBuilder
configuration.
Errors
This method fails if native TLS backend cannot be initialized.
Panics
This method consumes the internal state of the builder.
Trying to use this builder again after calling build
will panic.
pub fn add_root_certificate(&mut self, cert: Certificate) -> &mut ClientBuilder
[src]
pub fn add_root_certificate(&mut self, cert: Certificate) -> &mut ClientBuilder
Add 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(&mut self, identity: Identity) -> &mut ClientBuilder
[src]
pub fn identity(&mut self, identity: Identity) -> &mut ClientBuilder
Sets 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_disable_hostname_verification(&mut self) -> &mut ClientBuilder
[src]
pub fn danger_disable_hostname_verification(&mut self) -> &mut ClientBuilder
Disable hostname verification.
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 enable_hostname_verification(&mut self) -> &mut ClientBuilder
[src]
pub fn enable_hostname_verification(&mut self) -> &mut ClientBuilder
Enable hostname verification.
Default is enabled.
pub fn default_headers(&mut self, headers: Headers) -> &mut ClientBuilder
[src]
pub fn default_headers(&mut self, headers: Headers) -> &mut ClientBuilder
Sets the default headers for every request.
Example
use reqwest::header; let mut headers = header::Headers::new(); headers.set(header::Authorization("secret".to_string())); // 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::Headers::new(); headers.set(header::Authorization("secret".to_string())); // 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".to_string())) .send()?;
pub fn gzip(&mut self, enable: bool) -> &mut ClientBuilder
[src]
pub fn gzip(&mut self, enable: bool) -> &mut ClientBuilder
Enable auto gzip decompression by checking the ContentEncoding response header.
Default is enabled.
pub fn proxy(&mut self, proxy: Proxy) -> &mut ClientBuilder
[src]
pub fn proxy(&mut self, proxy: Proxy) -> &mut ClientBuilder
Add a Proxy
to the list of proxies the Client
will use.
pub fn redirect(&mut self, policy: RedirectPolicy) -> &mut ClientBuilder
[src]
pub fn redirect(&mut self, policy: RedirectPolicy) -> &mut ClientBuilder
Set a RedirectPolicy
for this client.
Default will follow redirects up to a maximum of 10.
pub fn referer(&mut self, enable: bool) -> &mut ClientBuilder
[src]
pub fn referer(&mut self, enable: bool) -> &mut ClientBuilder
Enable or disable automatic setting of the Referer
header.
Default is true
.
pub fn timeout<T>(&mut self, timeout: T) -> &mut ClientBuilder where
T: Into<Option<Duration>>,
[src]
pub fn timeout<T>(&mut self, timeout: T) -> &mut 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 ClientBuilder
Auto Trait Implementations
impl Send for ClientBuilder
impl Send for ClientBuilder
impl !Sync for ClientBuilder
impl !Sync for ClientBuilder