Struct reqwest::ClientBuilder [] [src]

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]

Constructs a new ClientBuilder

Errors

This method fails if native TLS backend cannot be created.

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.

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::ClientBuilder::new()?
    .add_root_certificate(cert)?
    .build()?;

Errors

This method fails if adding root certificate was unsuccessful.

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.

Enable hostname verification.

Default is enabled.

Enable auto gzip decompression by checking the ContentEncoding response header.

Default is enabled.

Add a Proxy to the list of proxies the Client will use.

Set a RedirectPolicy for this client.

Default will follow redirects up to a maximum of 10.

Enable or disable automatic setting of the Referer header.

Default is true.

Set a timeout for connect, read and write operations of a Client.

Trait Implementations

impl Debug for ClientBuilder
[src]

Formats the value using the given formatter.