# Struct reqwest::ClientBuilder [−] [src]

    #[must_use]pub struct ClientBuilder { /* fields omitted */ }

A `ClientBuilder` can be used to create a `Client` with custom configuration.

## 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::Client::builder()
        .user_agent(APP_USER_AGENT)
        .build()?;
    let res = client.get("https://www.rust-lang.org").send().await?;

#### `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("X-MY-HEADER", header::HeaderValue::from_static("value"));

    // Consider marking security-sensitive headers with `set_sensitive`.
    let mut auth_value = header::HeaderValue::from_static("secret");
    auth_value.set_sensitive(true);
    headers.insert(header::AUTHORIZATION, auth_value);

    // get a client builder
    let client = reqwest::Client::builder()
        .default_headers(headers)
        .build()?;
    let res = client.get("https://www.rust-lang.org").send().await?;

Override the default headers:

    use reqwest::header;
    let mut headers = header::HeaderMap::new();
    headers.insert("X-MY-HEADER", header::HeaderValue::from_static("value"));

    // get a client builder
    let client = reqwest::Client::builder()
        .default_headers(headers)
        .build()?;
    let res = client
        .get("https://www.rust-lang.org")
        .header("X-MY-HEADER", "new_value")
        .send()
        .await?;

#### `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 no_brotli(self) -> ClientBuilder` [src]

Disable auto response body brotli decompression.

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

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

Set a `RedirectPolicy` 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(self, timeout: Duration) -> ClientBuilder` [src]

Enables a request timeout.

The timeout is applied from when the request starts connecting until the response body has finished.

Default is no timeout.

#### `pub fn connect_timeout(self, timeout: Duration) -> ClientBuilder` [src]

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

Default is `None`.

# Note

This requires the futures be executed in a tokio runtime with a tokio timer enabled.

#### `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 http2_adaptive_window(self, enabled: bool) -> ClientBuilder` [src]

Sets whether to use an adaptive flow control.

Enabling this will override the limits set in `http2_initial_stream_window_size` and `http2_initial_connection_window_size`.

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

Sets the maximum frame size to use for HTTP2.

Default is currently 16,384 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::Client::builder()
        .local_address(local_addr)
        .build().unwrap();

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

Set that all sockets have `SO_KEEPALIVE` set with the supplied duration.

If `None`, the option will not be set.

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

Add a custom root certificate.

This can be used to connect to a server that has a self-signed certificate for example.

# Optional

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

#### `pub fn tls_built_in_root_certs(
self,
tls_built_in_root_certs: bool
) -> ClientBuilder` [src]

Controls the use of built-in/preloaded certificates during certificate validation.

Defaults to `true` – built-in system certs will be used.

# Optional

This requires the optional `default-tls`, `native-tls`, or `rustls-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.

# Optional

This requires the optional `default-tls`, `native-tls`, or `rustls-tls(-...)` 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.

#### `pub fn https_only(self, enabled: bool) -> ClientBuilder` [src]

Restrict the Client to be used with HTTPS only requests.

Defaults to false.

## Trait Implementations

### `impl Debug for ClientBuilder` [src]

#### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` [src]

Formats the value using the given formatter. Read more

### `impl Default for ClientBuilder` [src]

#### `fn default() -> Self` [src]

Returns the “default value” for a type. Read more

## Auto Trait Implementations

### `impl !RefUnwindSafe for ClientBuilder`

### `impl Send for ClientBuilder`

### `impl Sync for ClientBuilder`

### `impl Unpin for ClientBuilder`

### `impl !UnwindSafe for ClientBuilder`

## Blanket Implementations

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

#### `pub fn type_id(&self) -> TypeId` [src]

Gets the `TypeId` of `self`. Read more

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

#### `pub fn borrow(&self) -> &T` [src]

Immutably borrows from an owned value. Read more

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

#### `pub fn borrow_mut(&mut self) -> &mut T` [src]

Mutably borrows from an owned value. Read more

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

#### `pub fn from(t: T) -> T` [src]

Performs the conversion.

### `impl<T> Instrument for T` [src]

#### `pub fn instrument(self, span: Span) -> Instrumented<Self>` [src]

Instruments this type with the provided `Span`, returning an `Instrumented` wrapper. Read more

#### `pub fn in_current_span(self) -> Instrumented<Self>` [src]

Instruments this type with the current `Span`, returning an `Instrumented` wrapper. Read more

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

#### `pub fn into(self) -> U` [src]

Performs the conversion.

### `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.

#### `pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>` [src]

Performs the conversion.

### `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.

#### `pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>` [src]

Performs the conversion.