Struct Builder
struct Builder { ... }
A builder to configure a new Client.
Example
#
#
#
Implementations
impl Builder
fn new<E>(executor: E) -> Self where E: Executor<Pin<Box<dyn Future<Output = ()> + Send>>> + Send + Sync + Clone + 'staticConstruct a new Builder.
fn pool_idle_timeout<D>(self: &mut Self, val: D) -> &mut Self where D: Into<Option<Duration>>Set an optional timeout for idle sockets being kept-alive. A
Timeris required for this to take effect. SeeBuilder::pool_timerPass
Noneto disable timeout.Default is 90 seconds.
Example
# # #fn pool_max_idle_per_host(self: &mut Self, max_idle: usize) -> &mut SelfSets the maximum idle connection per host allowed in the pool.
Default is
usize::MAX(no limit).fn http1_read_buf_exact_size(self: &mut Self, sz: usize) -> &mut SelfSets the exact size of the read buffer to always use.
Note that setting this option unsets the
http1_max_buf_sizeoption.Default is an adaptive read buffer.
fn http1_max_buf_size(self: &mut Self, max: usize) -> &mut SelfSet the maximum buffer size for the connection.
Default is ~400kb.
Note that setting this option unsets the
http1_read_exact_buf_sizeoption.Panics
The minimum value allowed is 8192. This method panics if the passed
maxis less than the minimum.fn http1_allow_spaces_after_header_name_in_responses(self: &mut Self, val: bool) -> &mut SelfSet whether HTTP/1 connections will accept spaces between header names and the colon that follow them in responses.
Newline codepoints (
\rand\n) will be transformed to spaces when parsing.You probably don't need this, here is what RFC 7230 Section 3.2.4. has to say about it:
No whitespace is allowed between the header field-name and colon. In the past, differences in the handling of such whitespace have led to security vulnerabilities in request routing and response handling. A server MUST reject any received request message that contains whitespace between a header field-name and colon with a response code of 400 (Bad Request). A proxy MUST remove any such whitespace from a response message before forwarding the message downstream.
Note that this setting does not affect HTTP/2.
Default is false.
fn http1_allow_obsolete_multiline_headers_in_responses(self: &mut Self, val: bool) -> &mut SelfSet whether HTTP/1 connections will accept obsolete line folding for header values.
You probably don't need this, here is what RFC 7230 Section 3.2.4. has to say about it:
A server that receives an obs-fold in a request message that is not within a message/http container MUST either reject the message by sending a 400 (Bad Request), preferably with a representation explaining that obsolete line folding is unacceptable, or replace each received obs-fold with one or more SP octets prior to interpreting the field value or forwarding the message downstream.
A proxy or gateway that receives an obs-fold in a response message that is not within a message/http container MUST either discard the message and replace it with a 502 (Bad Gateway) response, preferably with a representation explaining that unacceptable line folding was received, or replace each received obs-fold with one or more SP octets prior to interpreting the field value or forwarding the message downstream.
A user agent that receives an obs-fold in a response message that is not within a message/http container MUST replace each received obs-fold with one or more SP octets prior to interpreting the field value.
Note that this setting does not affect HTTP/2.
Default is false.
fn http1_ignore_invalid_headers_in_responses(self: &mut Self, val: bool) -> &mut BuilderSets whether invalid header lines should be silently ignored in HTTP/1 responses.
This mimics the behaviour of major browsers. You probably don't want this. You should only want this if you are implementing a proxy whose main purpose is to sit in front of browsers whose users access arbitrary content which may be malformed, and they expect everything that works without the proxy to keep working with the proxy.
This option will prevent Hyper's client from returning an error encountered when parsing a header, except if the error was caused by the character NUL (ASCII code 0), as Chrome specifically always reject those.
The ignorable errors are:
- empty header names;
- characters that are not allowed in header names, except for
\0and\r; - when
allow_spaces_after_header_name_in_responsesis not enabled, spaces and tabs between the header name and the colon; - missing colon between header name and colon;
- characters that are not allowed in header values except for
\0and\r.
If an ignorable error is encountered, the parser tries to find the next line in the input to resume parsing the rest of the headers. An error will be emitted nonetheless if it finds
\0or a lone\rwhile looking for the next line.fn http1_writev(self: &mut Self, enabled: bool) -> &mut BuilderSet whether HTTP/1 connections should try to use vectored writes, or always flatten into a single buffer.
Note that setting this to false may mean more copies of body data, but may also improve performance when an IO transport doesn't support vectored writes well, such as most TLS implementations.
Setting this to true will force hyper to use queued strategy which may eliminate unnecessary cloning on some TLS backends
Default is
auto. In this mode hyper will try to guess which mode to usefn http1_title_case_headers(self: &mut Self, val: bool) -> &mut SelfSet whether HTTP/1 connections will write header names as title case at the socket level.
Note that this setting does not affect HTTP/2.
Default is false.
fn http1_preserve_header_case(self: &mut Self, val: bool) -> &mut SelfSet whether to support preserving original header cases.
Currently, this will record the original cases received, and store them in a private extension on the
Response. It will also look for and use such an extension in any providedRequest.Since the relevant extension is still private, there is no way to interact with the original cases. The only effect this can have now is to forward the cases in a proxy-like fashion.
Note that this setting does not affect HTTP/2.
Default is false.
fn http1_max_headers(self: &mut Self, val: usize) -> &mut SelfSet the maximum number of headers.
When a response is received, the parser will reserve a buffer to store headers for optimal performance.
If client receives more headers than the buffer size, the error "message header too large" is returned.
The headers is allocated on the stack by default, which has higher performance. After setting this value, headers will be allocated in heap memory, that is, heap memory allocation will occur for each response, and there will be a performance drop of about 5%.
Note that this setting does not affect HTTP/2.
Default is 100.
fn http09_responses(self: &mut Self, val: bool) -> &mut SelfSet whether HTTP/0.9 responses should be tolerated.
Default is false.
fn http2_only(self: &mut Self, val: bool) -> &mut SelfSet whether the connection must use HTTP/2.
The destination must either allow HTTP2 Prior Knowledge, or the
Connectshould be configured to do use ALPN to upgrade toh2as part of the connection process. This will not make theClientutilize ALPN by itself.Note that setting this to true prevents HTTP/1 from being allowed.
Default is false.
fn http2_max_pending_accept_reset_streams<impl Into<Option<usize>>: Into<Option<usize>>>(self: &mut Self, max: impl Into<Option<usize>>) -> &mut SelfConfigures the maximum number of pending reset streams allowed before a GOAWAY will be sent.
This will default to the default value set by the
h2crate. As of v0.4.0, it is 20.See https://github.com/hyperium/hyper/issues/2877 for more information.
fn http2_initial_stream_window_size<impl Into<Option<u32>>: Into<Option<u32>>>(self: &mut Self, sz: impl Into<Option<u32>>) -> &mut SelfSets the
SETTINGS_INITIAL_WINDOW_SIZEoption for HTTP2 stream-level flow control.Passing
Nonewill do nothing.If not set, hyper will use a default.
fn http2_initial_connection_window_size<impl Into<Option<u32>>: Into<Option<u32>>>(self: &mut Self, sz: impl Into<Option<u32>>) -> &mut SelfSets the max connection-level flow control for HTTP2
Passing
Nonewill do nothing.If not set, hyper will use a default.
fn http2_initial_max_send_streams<impl Into<Option<usize>>: Into<Option<usize>>>(self: &mut Self, initial: impl Into<Option<usize>>) -> &mut SelfSets the initial maximum of locally initiated (send) streams.
This value will be overwritten by the value included in the initial SETTINGS frame received from the peer as part of a connection preface.
Passing
Nonewill do nothing.If not set, hyper will use a default.
fn http2_adaptive_window(self: &mut Self, enabled: bool) -> &mut SelfSets whether to use an adaptive flow control.
Enabling this will override the limits set in
http2_initial_stream_window_sizeandhttp2_initial_connection_window_size.fn http2_max_frame_size<impl Into<Option<u32>>: Into<Option<u32>>>(self: &mut Self, sz: impl Into<Option<u32>>) -> &mut SelfSets the maximum frame size to use for HTTP2.
Passing
Nonewill do nothing.If not set, hyper will use a default.
fn http2_max_header_list_size(self: &mut Self, max: u32) -> &mut SelfSets the max size of received header frames for HTTP2.
Default is currently 16KB, but can change.
fn http2_keep_alive_interval<impl Into<Option<Duration>>: Into<Option<Duration>>>(self: &mut Self, interval: impl Into<Option<Duration>>) -> &mut SelfSets an interval for HTTP2 Ping frames should be sent to keep a connection alive.
Pass
Noneto disable HTTP2 keep-alive.Default is currently disabled.
Cargo Feature
Requires the
tokiocargo feature to be enabled.fn http2_keep_alive_timeout(self: &mut Self, timeout: Duration) -> &mut SelfSets a timeout for receiving an acknowledgement of the keep-alive ping.
If the ping is not acknowledged within the timeout, the connection will be closed. Does nothing if
http2_keep_alive_intervalis disabled.Default is 20 seconds.
Cargo Feature
Requires the
tokiocargo feature to be enabled.fn http2_keep_alive_while_idle(self: &mut Self, enabled: bool) -> &mut SelfSets whether HTTP2 keep-alive should apply while the connection is idle.
If disabled, keep-alive pings are only sent while there are open request/responses streams. If enabled, pings are also sent when no streams are active. Does nothing if
http2_keep_alive_intervalis disabled.Default is
false.Cargo Feature
Requires the
tokiocargo feature to be enabled.fn http2_max_concurrent_reset_streams(self: &mut Self, max: usize) -> &mut SelfSets the maximum number of HTTP2 concurrent locally reset streams.
See the documentation of
h2::client::Builder::max_concurrent_reset_streamsfor more details.The default value is determined by the
h2crate.fn timer<M>(self: &mut Self, timer: M) -> &mut Self where M: Timer + Send + Sync + 'staticProvide a timer to be used for h2
See the documentation of
h2::client::Builder::timerfor more details.fn pool_timer<M>(self: &mut Self, timer: M) -> &mut Self where M: Timer + Clone + Send + Sync + 'staticProvide a timer to be used for timeouts and intervals in connection pools.
fn http2_max_send_buf_size(self: &mut Self, max: usize) -> &mut SelfSet the maximum write buffer size for each HTTP/2 stream.
Default is currently 1MB, but may change.
Panics
The value must be no larger than
u32::MAX.fn retry_canceled_requests(self: &mut Self, val: bool) -> &mut SelfSet whether to retry requests that get disrupted before ever starting to write.
This means a request that is queued, and gets given an idle, reused connection, and then encounters an error immediately as the idle connection was found to be unusable.
When this is set to
false, the relatedResponseFuturewould instead resolve to anError::Cancel.Default is
true.fn set_host(self: &mut Self, val: bool) -> &mut SelfSet whether to automatically add the
Hostheader to requests.If true, and a request does not include a
Hostheader, one will be added automatically, derived from the authority of theUri.Default is
true.fn build_http<B>(self: &Self) -> Client<HttpConnector, B> where B: Body + Send, <B as >::Data: SendBuild a client with this configuration and the default
HttpConnector.fn build<C, B>(self: &Self, connector: C) -> Client<C, B> where C: Connect + Clone, B: Body + Send, <B as >::Data: SendCombine the configuration of this builder with a connector to create a
Client.
impl Clone for Builder
fn clone(self: &Self) -> Builder
impl Debug for Builder
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
impl UnwindSafe for Builder
impl<T> Any for Builder
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Builder
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Builder
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Builder
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Builder
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for Builder
impl<T> ToOwned for Builder
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> WithSubscriber for Builder
impl<T, U> Into for Builder
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Builder
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Builder
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>