[go: up one dir, main page]

ConfigBuilder

Struct ConfigBuilder 

Source
pub struct ConfigBuilder<Scope: ConfigScope>(/* private fields */);
Expand description

Builder of Config

Implementations§

Source§

impl<Scope: ConfigScope> ConfigBuilder<Scope>

Source

pub fn http_status_as_error(self, v: bool) -> Self

Whether to treat 4xx and 5xx HTTP status codes as Err(Error::StatusCode)).

Defaults to true.

Source

pub fn https_only(self, v: bool) -> Self

Whether to limit requests (including redirects) to https only

Defaults to false.

Source

pub fn ip_family(self, v: IpFamily) -> Self

Configuration of IPv4/IPv6.

This affects the resolver.

Defaults to IpFamily::Any.

Source

pub fn tls_config(self, v: TlsConfig) -> Self

Config for TLS.

This config is generic for all TLS connectors.

Source

pub fn proxy(self, v: Option<Proxy>) -> Self

Proxy configuration.

Picked up from environment when using Config::default() or Agent::new_with_defaults().

Source

pub fn no_delay(self, v: bool) -> Self

Disable Nagle’s algorithm

Set TCP_NODELAY. It’s up to the transport whether this flag is honored.

Defaults to true.

Source

pub fn max_redirects(self, v: u32) -> Self

The max number of redirects to follow before giving up.

Whe max redirects are reached, the behavior is controlled by the max_redirects_will_error setting. Set to true (which is the default) the result is a TooManyRedirects error. Set to false, the response is returned as is.

If max_redirects is 0, no redirects are followed and the response is always returned (never a TooManyRedirects error).

Defaults to 10

Source

pub fn max_redirects_will_error(self, v: bool) -> Self

If we should error when max redirects are reached.

This has no meaning if max_redirects is 0.

Defaults to true

Source

pub fn redirect_auth_headers(self, v: RedirectAuthHeaders) -> Self

How to handle Authorization headers when following redirects

  • Never (the default) means the authorization header is never attached to a redirected call.
  • SameHost will keep the header when the redirect is to the same host and under https.

Defaults to None.

Source

pub fn save_redirect_history(self, v: bool) -> Self

If we should record a history of every redirect location, including the request and final locations.

Comes at the cost of allocating/retaining the Uri for every redirect loop.

See ResponseExt::get_redirect_history().

Defaults to false.

Source

pub fn user_agent(self, v: impl Into<AutoHeaderValue>) -> Self

Value to use for the User-Agent header.

This can be overridden by setting a user-agent header on the request object. The one difference is that a connection to a HTTP proxy server will receive this value, not the request-level one.

Setting a value of "" on the request or agent level will also not send a header.

Defaults to Default, which results in ureq/<version>

Source

pub fn accept(self, v: impl Into<AutoHeaderValue>) -> Self

Value to use for the Accept header.

This agent configured value can be overriden per request by setting the header. Setting a value of "" on the request or agent level will also not send a header.

Defaults to Default, which results in */*

Source

pub fn accept_encoding(self, v: impl Into<AutoHeaderValue>) -> Self

Value to use for the Accept-Encoding header.

Defaults to Default, which will add gz and brotli depending on the feature flags gzip and brotli respectively. If neither feature is enabled, the header is not added.

This agent configured value can be overriden per request by setting the header.

Setting a value of "" on the request or agent level will also not send a header.

This communicates capability to the server, however the triggering the automatic decompression behavior is not affected since that only looks at the Content-Encoding response header.

Source

pub fn max_response_header_size(self, v: usize) -> Self

Max size of the HTTP response header.

From the status, including all headers up until the body.

Defaults to 64kb.

Source

pub fn input_buffer_size(self, v: usize) -> Self

Default size of the input buffer

The default connectors use this setting.

Defaults to 128kb.

Source

pub fn output_buffer_size(self, v: usize) -> Self

Default size of the output buffer.

The default connectors use this setting.

Defaults to 128kb.

Source

pub fn max_idle_connections(self, v: usize) -> Self

Max number of idle pooled connections overall.

This setting has no effect when used per-request.

Defaults to 10

Source

pub fn max_idle_connections_per_host(self, v: usize) -> Self

Max number of idle pooled connections per host/port combo.

This setting has no effect when used per-request.

Defaults to 3

Source

pub fn max_idle_age(self, v: Duration) -> Self

Max duration to keep an idle connection in the pool

This can also be configured per-request to be shorter than the pool. For example: if the pool is configured to 15 seconds and we have a connection with an age of 10 seconds, a request setting this config property to 3 seconds, would ignore the pooled connection (but still leave it in the pool).

Defaults to 15 seconds

Source

pub fn allow_non_standard_methods(self, v: bool) -> Self

Whether to allow non-standard HTTP methods.

By default the methods are limited by the HTTP version.

Defaults to false

Source

pub fn middleware(self, v: impl Middleware) -> Self

Add middleware to use for each request in this agent.

Defaults to no middleware.

Source

pub fn timeout_global(self, v: Option<Duration>) -> Self

Timeout for the entire call

This is end-to-end, from DNS lookup to finishing reading the response body. Thus it covers all other timeouts.

Defaults to None.

Source

pub fn timeout_per_call(self, v: Option<Duration>) -> Self

Timeout for call-by-call when following redirects

This covers a single call and the timeout is reset when ureq follows a redirections.

Defaults to None..

Source

pub fn timeout_resolve(self, v: Option<Duration>) -> Self

Max duration for doing the DNS lookup when establishing the connection

Because most platforms do not have an async syscall for looking up a host name, setting this might force str0m to spawn a thread to handle the timeout.

Defaults to None.

Source

pub fn timeout_connect(self, v: Option<Duration>) -> Self

Max duration for establishing the connection

For a TLS connection this includes opening the socket and doing the TLS handshake.

Defaults to None.

Source

pub fn timeout_send_request(self, v: Option<Duration>) -> Self

Max duration for sending the request, but not the request body.

Defaults to None.

Source

pub fn timeout_await_100(self, v: Option<Duration>) -> Self

Max duration for awaiting a 100-continue response.

Only used if there is a request body and we sent the Expect: 100-continue header to indicate we want the server to respond with 100.

This defaults to 1 second.

Source

pub fn timeout_send_body(self, v: Option<Duration>) -> Self

Max duration for sending a request body (if there is one)

Defaults to None.

Source

pub fn timeout_recv_response(self, v: Option<Duration>) -> Self

Max duration for receiving the response headers, but not the body

Defaults to None.

Source

pub fn timeout_recv_body(self, v: Option<Duration>) -> Self

Max duration for receving the response body.

Defaults to None.

Source§

impl ConfigBuilder<AgentScope>

Source

pub fn build(self) -> Config

Finalize the config

Source§

impl<Any> ConfigBuilder<RequestScope<Any>>

Source

pub fn build(self) -> RequestBuilder<Any>

Finalize the config

Source§

impl<S: AsSendBody> ConfigBuilder<HttpCrateScope<S>>

Source

pub fn build(self) -> Request<S>

Finalize the config

Source§

impl<'a, S: AsSendBody> ConfigBuilder<RequestExtScope<'a, S>>

Source

pub fn build(self) -> WithAgent<'a, S>

Finalize the config

Source

pub fn run(self) -> Result<Response<Body>, Error>

Run the request with the agent in the ConfigBuilder

Auto Trait Implementations§

§

impl<Scope> Freeze for ConfigBuilder<Scope>
where Scope: Freeze,

§

impl<Scope> RefUnwindSafe for ConfigBuilder<Scope>
where Scope: RefUnwindSafe,

§

impl<Scope> Send for ConfigBuilder<Scope>
where Scope: Send,

§

impl<Scope> Sync for ConfigBuilder<Scope>
where Scope: Sync,

§

impl<Scope> Unpin for ConfigBuilder<Scope>
where Scope: Unpin,

§

impl<Scope> UnwindSafe for ConfigBuilder<Scope>
where Scope: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.