[][src]Struct chttp::client::ClientBuilder

pub struct ClientBuilder { /* fields omitted */ }

An HTTP client builder, capable of creating custom Client instances with customized behavior.

Example:

use chttp::{http, Client, Options, RedirectPolicy};
use std::time::Duration;

let client = Client::builder()
    .options(Options::default()
        .with_timeout(Some(Duration::from_secs(60)))
        .with_redirect_policy(RedirectPolicy::Limit(10))
        .with_preferred_http_version(Some(http::Version::HTTP_2)))
    .build()?;

let mut response = client.get("https://example.org")?;
let body = response.body_mut().text()?;
println!("{}", body);

Methods

impl ClientBuilder[src]

pub fn new() -> Self[src]

Create a new builder for building a custom client.

pub fn options(self, options: Options) -> Self[src]

Set the default connection options to use for each request.

If a request has custom options, then they will override any options specified here.

pub fn with_cookies(self) -> Self[src]

Enable persistent cookie handling using a cookie jar.

pub fn with_middleware(self, middleware: impl Middleware) -> Self[src]

Add a middleware layer to the client.

pub fn build(&mut self) -> Result<Client, Error>[src]

Build an HTTP client using the configured options.

If the client fails to initialize, an error will be returned.

Trait Implementations

impl Default for ClientBuilder[src]

Auto Trait Implementations

Blanket Implementations

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

impl<T> From for T[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

impl<T, U> TryInto 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<T> Any for T where
    T: 'static + ?Sized
[src]