Struct nightfly_twitchax_patch::ClientBuilder
source · pub struct ClientBuilder { /* private fields */ }Expand description
A ClientBuilder can be used to create a Client with custom configuration.
Implementations§
source§impl ClientBuilder
impl ClientBuilder
sourcepub fn new() -> ClientBuilder
pub fn new() -> ClientBuilder
Constructs a new ClientBuilder.
This is the same as Client::builder().
sourcepub fn build(self) -> Result<Client>
pub fn build(self) -> Result<Client>
Returns a Client that uses this ClientBuilder configuration.
Errors
This method fails if a TLS backend cannot be initialized, or the resolver cannot load the system configuration.
sourcepub fn user_agent<V>(self, value: V) -> ClientBuilder
pub fn user_agent<V>(self, value: V) -> ClientBuilder
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 = nightfly::Client::builder()
.user_agent(APP_USER_AGENT)
.build()?;
let res = client.get("https://www.rust-lang.org").send();sourcepub fn default_headers(self, headers: HeaderMap) -> ClientBuilder
pub fn default_headers(self, headers: HeaderMap) -> ClientBuilder
Sets the default headers for every request.
Example
use nightfly::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 = nightfly::Client::builder()
.default_headers(headers)
.build()?;
let res = client.get("https://www.rust-lang.org").send();Override the default headers:
use nightfly::header;
let mut headers = header::HeaderMap::new();
headers.insert("X-MY-HEADER", header::HeaderValue::from_static("value"));
// get a client builder
let client = nightfly::Client::builder()
.default_headers(headers)
.build()?;
let res = client
.get("https://www.rust-lang.org")
.header("X-MY-HEADER", "new_value")
.send()
;sourcepub fn gzip(self, enable: bool) -> ClientBuilder
pub fn gzip(self, enable: bool) -> ClientBuilder
Enable auto gzip decompression by checking the Content-Encoding response header.
If auto gzip decompression is turned on:
- When sending a request and if the request’s headers do not already contain
an
Accept-EncodingandRangevalues, theAccept-Encodingheader is set togzip. The request body is not automatically compressed. - When receiving a response, if its headers contain a
Content-Encodingvalue ofgzip, bothContent-EncodingandContent-Lengthare removed from the headers’ set. The response body is automatically decompressed.
If the gzip feature is turned on, the default option is enabled.
sourcepub fn brotli(self, enable: bool) -> ClientBuilder
pub fn brotli(self, enable: bool) -> ClientBuilder
Enable auto brotli decompression by checking the Content-Encoding response header.
If auto brotli decompression is turned on:
- When sending a request and if the request’s headers do not already contain
an
Accept-EncodingandRangevalues, theAccept-Encodingheader is set tobr. The request body is not automatically compressed. - When receiving a response, if its headers contain a
Content-Encodingvalue ofbr, bothContent-EncodingandContent-Lengthare removed from the headers’ set. The response body is automatically decompressed.
sourcepub fn deflate(self, enable: bool) -> ClientBuilder
pub fn deflate(self, enable: bool) -> ClientBuilder
Enable auto deflate decompression by checking the Content-Encoding response header.
If auto deflate decompression is turned on:
- When sending a request and if the request’s headers do not already contain
an
Accept-EncodingandRangevalues, theAccept-Encodingheader is set todeflate. The request body is not automatically compressed. - When receiving a response, if it’s headers contain a
Content-Encodingvalue that equals todeflate, both valuesContent-EncodingandContent-Lengthare removed from the headers’ set. The response body is automatically decompressed.
sourcepub fn no_gzip(self) -> ClientBuilder
pub fn no_gzip(self) -> ClientBuilder
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.
sourcepub fn no_brotli(self) -> ClientBuilder
pub fn no_brotli(self) -> ClientBuilder
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.
sourcepub fn no_deflate(self) -> ClientBuilder
pub fn no_deflate(self) -> ClientBuilder
Disable auto response body deflate decompression.
This method exists even if the optional deflate feature is not enabled.
This can be used to ensure a Client doesn’t use deflate decompression
even if another dependency were to enable the optional deflate feature.
sourcepub fn redirect(self, policy: Policy) -> ClientBuilder
pub fn redirect(self, policy: Policy) -> ClientBuilder
Set a RedirectPolicy for this client.
Default will follow redirects up to a maximum of 10.
sourcepub fn referer(self, enable: bool) -> ClientBuilder
pub fn referer(self, enable: bool) -> ClientBuilder
Enable or disable automatic setting of the Referer header.
Default is true.
sourcepub fn timeout(self, timeout: Duration) -> ClientBuilder
pub fn timeout(self, timeout: Duration) -> ClientBuilder
Enables a request timeout.
The timeout is applied from when the request starts connecting until the response body has finished.
Default is no timeout.
sourcepub fn connect_timeout(self, timeout: Duration) -> ClientBuilder
pub fn connect_timeout(self, timeout: Duration) -> ClientBuilder
Set a timeout for only the connect phase of a Client.
Default is None.
sourcepub fn connection_verbose(self, verbose: bool) -> ClientBuilder
pub fn connection_verbose(self, verbose: bool) -> ClientBuilder
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.
sourcepub fn pool_idle_timeout<D>(self, val: D) -> ClientBuilder
pub fn pool_idle_timeout<D>(self, val: D) -> ClientBuilder
Set an optional timeout for idle sockets being kept-alive.
Pass None to disable timeout.
Default is 90 seconds.
sourcepub fn pool_max_idle_per_host(self, max: usize) -> ClientBuilder
pub fn pool_max_idle_per_host(self, max: usize) -> ClientBuilder
Sets the maximum idle connection per host allowed in the pool.
sourcepub fn http1_title_case_headers(self) -> ClientBuilder
pub fn http1_title_case_headers(self) -> ClientBuilder
Send headers as title case instead of lowercase.
sourcepub fn http1_allow_obsolete_multiline_headers_in_responses(
self,
value: bool
) -> ClientBuilder
pub fn http1_allow_obsolete_multiline_headers_in_responses( self, value: bool ) -> ClientBuilder
Set whether HTTP/1 connections will accept obsolete line folding for header values.
Newline codepoints (\r and \n) will be transformed to spaces when
parsing.
sourcepub fn http1_only(self) -> ClientBuilder
pub fn http1_only(self) -> ClientBuilder
Only use HTTP/1.
sourcepub fn http09_responses(self) -> ClientBuilder
pub fn http09_responses(self) -> ClientBuilder
Allow HTTP/0.9 responses
sourcepub fn http2_prior_knowledge(self) -> ClientBuilder
pub fn http2_prior_knowledge(self) -> ClientBuilder
Only use HTTP/2.
sourcepub fn http2_initial_stream_window_size(
self,
sz: impl Into<Option<u32>>
) -> ClientBuilder
pub fn http2_initial_stream_window_size( self, sz: impl Into<Option<u32>> ) -> ClientBuilder
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.
sourcepub fn http2_initial_connection_window_size(
self,
sz: impl Into<Option<u32>>
) -> ClientBuilder
pub fn http2_initial_connection_window_size( self, sz: impl Into<Option<u32>> ) -> ClientBuilder
Sets the max connection-level flow control for HTTP2
Default is currently 65,535 but may change internally to optimize for common uses.
sourcepub fn http2_adaptive_window(self, enabled: bool) -> ClientBuilder
pub fn http2_adaptive_window(self, enabled: bool) -> ClientBuilder
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.
sourcepub fn http2_max_frame_size(self, sz: impl Into<Option<u32>>) -> ClientBuilder
pub fn http2_max_frame_size(self, sz: impl Into<Option<u32>>) -> ClientBuilder
Sets the maximum frame size to use for HTTP2.
Default is currently 16,384 but may change internally to optimize for common uses.
sourcepub fn http2_keep_alive_interval(
self,
interval: impl Into<Option<Duration>>
) -> ClientBuilder
pub fn http2_keep_alive_interval( self, interval: impl Into<Option<Duration>> ) -> ClientBuilder
Sets an interval for HTTP2 Ping frames should be sent to keep a connection alive.
Pass None to disable HTTP2 keep-alive.
Default is currently disabled.
sourcepub fn http2_keep_alive_timeout(self, timeout: Duration) -> ClientBuilder
pub fn http2_keep_alive_timeout(self, timeout: Duration) -> ClientBuilder
Sets 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_interval is disabled.
Default is currently disabled.
sourcepub fn http2_keep_alive_while_idle(self, enabled: bool) -> ClientBuilder
pub fn http2_keep_alive_while_idle(self, enabled: bool) -> ClientBuilder
Sets 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_interval is disabled.
Default is false.
sourcepub fn tcp_nodelay(self, enabled: bool) -> ClientBuilder
pub fn tcp_nodelay(self, enabled: bool) -> ClientBuilder
Set whether sockets have SO_NODELAY enabled.
Default is true.
sourcepub fn local_address<T>(self, addr: T) -> ClientBuilder
pub fn local_address<T>(self, addr: T) -> ClientBuilder
Bind to a local IP Address.
Example
use std::net::IpAddr;
let local_addr = IpAddr::from([12, 4, 1, 8]);
let client = nightfly::Client::builder()
.local_address(local_addr)
.build().unwrap();sourcepub fn tcp_keepalive<D>(self, val: D) -> ClientBuilder
pub fn tcp_keepalive<D>(self, val: D) -> ClientBuilder
Set that all sockets have SO_KEEPALIVE set with the supplied duration.
If None, the option will not be set.
sourcepub fn no_trust_dns(self) -> ClientBuilder
pub fn no_trust_dns(self) -> ClientBuilder
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.
sourcepub fn https_only(self, enabled: bool) -> ClientBuilder
pub fn https_only(self, enabled: bool) -> ClientBuilder
Restrict the Client to be used with HTTPS only requests.
Defaults to false.
sourcepub fn resolve(self, domain: &str, addr: SocketAddr) -> ClientBuilder
pub fn resolve(self, domain: &str, addr: SocketAddr) -> ClientBuilder
Override DNS resolution for specific domains to a particular IP address.
Warning
Since the DNS protocol has no notion of ports, if you wish to send traffic to a particular port you must include this port in the URL itself, any port in the overridden addr will be ignored and traffic sent to the conventional port for the given scheme (e.g. 80 for http).
sourcepub fn resolve_to_addrs(
self,
domain: &str,
addrs: &[SocketAddr]
) -> ClientBuilder
pub fn resolve_to_addrs( self, domain: &str, addrs: &[SocketAddr] ) -> ClientBuilder
Override DNS resolution for specific domains to particular IP addresses.
Warning
Since the DNS protocol has no notion of ports, if you wish to send traffic to a particular port you must include this port in the URL itself, any port in the overridden addresses will be ignored and traffic sent to the conventional port for the given scheme (e.g. 80 for http).
Trait Implementations§
source§impl Clone for ClientBuilder
impl Clone for ClientBuilder
source§fn clone(&self) -> ClientBuilder
fn clone(&self) -> ClientBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more