[][src]Struct reqwest::blocking::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::blocking::Client::builder()
    .timeout(Duration::from_secs(10))
    .build()?;

Implementations

impl ClientBuilder[src]

pub fn new() -> ClientBuilder[src]

Constructs a new ClientBuilder.

This is the same as Client::builder().

pub fn build(self) -> Result<Client>[src]

Returns a Client that uses this ClientBuilder configuration.

Errors

This method fails if TLS backend cannot be initialized, or the resolver cannot load the system configuration.

pub fn user_agent<V>(self, value: V) -> ClientBuilder where
    V: TryInto<HeaderValue>,
    V::Error: Into<Error>, 
[src]

Sets the User-Agent header to be used by this client.

Example

// Name your user agent after your app?
static APP_USER_AGENT: &str = concat!(
    env!("CARGO_PKG_NAME"),
    "/",
    env!("CARGO_PKG_VERSION"),
);

let client = reqwest::blocking::Client::builder()
    .user_agent(APP_USER_AGENT)
    .build()?;
let res = client.get("https://www.rust-lang.org").send()?;

pub fn default_headers(self, headers: HeaderMap) -> ClientBuilder[src]

Sets 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::blocking::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::blocking::Client::builder()
    .default_headers(headers)
    .build()?;
let res = client
    .get("https://www.rust-lang.org")
    .header(header::AUTHORIZATION, "token")
    .send()?;

pub fn cookie_store(self, enable: bool) -> ClientBuilder[src]

Enable a persistent cookie store for the client.

Cookies received in responses will be preserved and included in additional requests.

By default, no cookie store is used.

Optional

This requires the optional cookies feature to be enabled.

pub fn gzip(self, enable: bool) -> ClientBuilder[src]

Enable auto gzip decompression by checking the Content-Encoding 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-Encoding and Range values, the Accept-Encoding header is set to gzip. The request body is not automatically compressed.
  • When receiving a response, if it's headers contain a Content-Encoding value that equals to gzip, both values Content-Encoding and Content-Length are removed from the headers' set. The response body is automatically decompressed.

If the gzip feature is turned on, the default option is enabled.

Optional

This requires the optional gzip feature to be enabled

pub fn no_gzip(self) -> ClientBuilder[src]

Disable auto response body gzip decompression.

This method exists even if the optional gzip feature is not enabled. This can be used to ensure a Client doesn't use gzip decompression even if another dependency were to enable the optional gzip feature.

pub fn redirect(self, policy: Policy) -> ClientBuilder[src]

Set a redirect::Policy for this client.

Default will follow redirects up to a maximum of 10.

pub fn referer(self, enable: bool) -> ClientBuilder[src]

Enable or disable automatic setting of the Referer header.

Default is true.

pub fn proxy(self, proxy: Proxy) -> ClientBuilder[src]

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

Note

Adding a proxy will disable the automatic usage of the "system" proxy.

pub fn no_proxy(self) -> ClientBuilder[src]

Clear all Proxies, so Client will use no proxy anymore.

This also disables the automatic usage of the "system" proxy.

pub fn timeout<T>(self, timeout: T) -> ClientBuilder where
    T: Into<Option<Duration>>, 
[src]

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

Default is 30 seconds.

Pass None to disable timeout.

pub fn connect_timeout<T>(self, timeout: T) -> ClientBuilder where
    T: Into<Option<Duration>>, 
[src]

Set a timeout for only the connect phase of a Client.

Default is None.

pub fn connection_verbose(self, verbose: bool) -> ClientBuilder[src]

Set whether connections should emit verbose logs.

Enabling this option will emit log messages at the TRACE level for read and write operations on connections.

pub fn pool_idle_timeout<D>(self, val: D) -> ClientBuilder where
    D: Into<Option<Duration>>, 
[src]

Set an optional timeout for idle sockets being kept-alive.

Pass None to disable timeout.

Default is 90 seconds.

pub fn pool_max_idle_per_host(self, max: usize) -> ClientBuilder[src]

Sets the maximum idle connection per host allowed in the pool.

pub fn http1_title_case_headers(self) -> ClientBuilder[src]

Enable case sensitive headers.

pub fn http2_prior_knowledge(self) -> ClientBuilder[src]

Only use HTTP/2.

pub fn http2_initial_stream_window_size(
    self,
    sz: impl Into<Option<u32>>
) -> ClientBuilder
[src]

Sets the SETTINGS_INITIAL_WINDOW_SIZE option for HTTP2 stream-level flow control.

Default is currently 65,535 but may change internally to optimize for common uses.

pub fn http2_initial_connection_window_size(
    self,
    sz: impl Into<Option<u32>>
) -> ClientBuilder
[src]

Sets the max connection-level flow control for HTTP2

Default is currently 65,535 but may change internally to optimize for common uses.

pub fn tcp_nodelay_(self, enabled: bool) -> ClientBuilder[src]

Set whether sockets have SO_NODELAY enabled.

Default is true.

pub fn local_address<T>(self, addr: T) -> ClientBuilder where
    T: Into<Option<IpAddr>>, 
[src]

Bind to a local IP Address.

Example

use std::net::IpAddr;
let local_addr = IpAddr::from([12, 4, 1, 8]);
let client = reqwest::blocking::Client::builder()
    .local_address(local_addr)
    .build().unwrap();

pub fn add_root_certificate(self, cert: Certificate) -> ClientBuilder[src]

Add a custom root certificate.

This allows connecting to a server that has a self-signed certificate for example. This does not replace the existing trusted store.

Example

// read a local binary DER encoded certificate
let der = std::fs::read("my-cert.der")?;

// create a certificate
let cert = reqwest::Certificate::from_der(&der)?;

// get a client builder
let client = reqwest::blocking::Client::builder()
    .add_root_certificate(cert)
    .build()?;

Optional

This requires the optional default-tls, native-tls, or rustls-tls feature to be enabled.

pub fn identity(self, identity: Identity) -> ClientBuilder[src]

Sets the identity to be used for client certificate authentication.

pub fn danger_accept_invalid_hostnames(
    self,
    accept_invalid_hostname: bool
) -> ClientBuilder
[src]

Controls 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.

Optional

This requires the optional native-tls feature to be enabled.

pub fn danger_accept_invalid_certs(
    self,
    accept_invalid_certs: bool
) -> ClientBuilder
[src]

Controls 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 use_native_tls(self) -> ClientBuilder[src]

Force using the native TLS backend.

Since multiple TLS backends can be optionally enabled, this option will force the native-tls backend to be used for this Client.

Optional

This requires the optional native-tls feature to be enabled.

pub fn use_rustls_tls(self) -> ClientBuilder[src]

Force using the Rustls TLS backend.

Since multiple TLS backends can be optionally enabled, this option will force the rustls backend to be used for this Client.

Optional

This requires the optional rustls-tls feature to be enabled.

pub fn use_preconfigured_tls(self, tls: impl Any) -> ClientBuilder[src]

Use a preconfigured TLS backend.

If the passed Any argument is not a TLS backend that reqwest understands, the ClientBuilder will error when calling build.

Advanced

This is an advanced option, and can be somewhat brittle. Usage requires keeping the preconfigured TLS argument version in sync with reqwest, since version mismatches will result in an "unknown" TLS backend.

If possible, it's preferable to use the methods on ClientBuilder to configure reqwest's TLS.

Optional

This requires one of the optional features native-tls or rustls-tls to be enabled.

pub fn trust_dns(self, enable: bool) -> ClientBuilder[src]

Enables the trust-dns async resolver instead of a default threadpool using getaddrinfo.

If the trust-dns feature is turned on, the default option is enabled.

Optional

This requires the optional trust-dns feature to be enabled

pub fn no_trust_dns(self) -> ClientBuilder[src]

Disables the trust-dns async resolver.

This method exists even if the optional trust-dns feature is not enabled. This can be used to ensure a Client doesn't use the trust-dns async resolver even if another dependency were to enable the optional trust-dns feature.

Trait Implementations

impl Debug for ClientBuilder[src]

impl Default for ClientBuilder[src]

impl From<ClientBuilder> for ClientBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Sealed<T> for T where
    T: ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,