Struct HttpConfig

Source
pub struct HttpConfig { /* private fields */ }
Expand description

Represents a configuration for the Http protocol. This allows for detailed customization of various HTTP/1 and HTTP/2 settings.

Implementations§

Source§

impl HttpConfig

Source

pub fn new() -> HttpConfig

Creates a new HttpConfig with default settings.

Examples found in repository?
examples/configure_http.rs (line 13)
10async fn main() {
11    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
12
13    let config = HttpConfig::new()
14        .http1_only(true)
15        .http2_only(false)
16        .max_buf_size(8192)
17        .build();
18
19    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
20    println!("listening on {}", addr);
21    hyper_server::bind(addr)
22        .http_config(config)
23        .serve(app.into_make_service())
24        .await
25        .unwrap();
26}
Source

pub fn build(&mut self) -> Self

Clones the current configuration state and returns it. Useful for building configurations dynamically.

Examples found in repository?
examples/configure_http.rs (line 17)
10async fn main() {
11    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
12
13    let config = HttpConfig::new()
14        .http1_only(true)
15        .http2_only(false)
16        .max_buf_size(8192)
17        .build();
18
19    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
20    println!("listening on {}", addr);
21    hyper_server::bind(addr)
22        .http_config(config)
23        .serve(app.into_make_service())
24        .await
25        .unwrap();
26}
Source

pub fn http1_only(&mut self, val: bool) -> &mut Self

Configures whether to exclusively support HTTP/1.

When enabled, only HTTP/1 requests are processed, and HTTP/2 requests are rejected.

Default is false.

Examples found in repository?
examples/configure_http.rs (line 14)
10async fn main() {
11    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
12
13    let config = HttpConfig::new()
14        .http1_only(true)
15        .http2_only(false)
16        .max_buf_size(8192)
17        .build();
18
19    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
20    println!("listening on {}", addr);
21    hyper_server::bind(addr)
22        .http_config(config)
23        .serve(app.into_make_service())
24        .await
25        .unwrap();
26}
Source

pub fn http1_half_close(&mut self, val: bool) -> &mut Self

Specifies if HTTP/1 connections should be allowed to use half-closures.

A half-closure in TCP occurs when one side of the data stream is terminated, but the other side remains open. This setting, when true, ensures the server doesn’t immediately close a connection if a client shuts down their sending side while waiting for a response.

Default is false.

Source

pub fn http1_keep_alive(&mut self, val: bool) -> &mut Self

Enables or disables the keep-alive feature for HTTP/1 connections.

Keep-alive allows the connection to be reused for multiple requests and responses.

Default is true.

Source

pub fn http1_title_case_headers(&mut self, enabled: bool) -> &mut Self

Determines if HTTP/1 connections should write headers with title-case naming.

For example, turning this setting true would send headers as “Content-Type” instead of “content-type”. Note that this has no effect on HTTP/2 connections.

Default is false.

Source

pub fn http1_preserve_header_case(&mut self, enabled: bool) -> &mut Self

Determines if HTTP/1 connections should preserve the original case of headers.

By default, headers might be normalized. Enabling this will ensure headers retain their original casing. This setting doesn’t influence HTTP/2.

Default is false.

Source

pub fn http1_header_read_timeout(&mut self, val: Duration) -> &mut Self

Configures a timeout for how long the server will wait for client headers.

If the client doesn’t send all headers within this duration, the connection is terminated.

Default is None, meaning no timeout.

Source

pub fn http1_writev(&mut self, val: bool) -> &mut Self

Specifies whether to use vectored writes for HTTP/1 connections.

Vectored writes can be efficient for multiple non-contiguous data segments. However, certain transports (like many TLS implementations) may not handle vectored writes well. When disabled, data is flattened into a single buffer before writing.

Default is auto, where the best method is determined dynamically.

Source

pub fn http2_only(&mut self, val: bool) -> &mut Self

Configures the server to exclusively support HTTP/2.

When enabled, only HTTP/2 requests are processed, and HTTP/1 requests are rejected.

Default is false.

Examples found in repository?
examples/configure_http.rs (line 15)
10async fn main() {
11    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
12
13    let config = HttpConfig::new()
14        .http1_only(true)
15        .http2_only(false)
16        .max_buf_size(8192)
17        .build();
18
19    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
20    println!("listening on {}", addr);
21    hyper_server::bind(addr)
22        .http_config(config)
23        .serve(app.into_make_service())
24        .await
25        .unwrap();
26}
Source

pub fn http2_initial_stream_window_size( &mut self, sz: impl Into<Option<u32>>, ) -> &mut Self

Sets the SETTINGS_INITIAL_WINDOW_SIZE option for HTTP2 stream-level flow control.

Passing None will do nothing.

If not set, hyper will use a default.

Source

pub fn http2_initial_connection_window_size( &mut self, sz: impl Into<Option<u32>>, ) -> &mut Self

Sets the max connection-level flow control for HTTP2.

Passing None will do nothing.

If not set, hyper will use a default.

Source

pub fn http2_adaptive_window(&mut self, enabled: bool) -> &mut Self

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.

Source

pub fn http2_enable_connect_protocol(&mut self) -> &mut Self

Source

pub fn http2_max_frame_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self

Sets the maximum frame size to use for HTTP2.

Passing None will do nothing.

If not set, hyper will use a default.

Source

pub fn http2_max_concurrent_streams( &mut self, max: impl Into<Option<u32>>, ) -> &mut Self

Sets the SETTINGS_MAX_CONCURRENT_STREAMS option for HTTP2 connections.

Default is no limit (std::u32::MAX). Passing None will do nothing.

Source

pub fn http2_max_header_list_size(&mut self, max: u32) -> &mut Self

Sets the max size of received header frames.

Default is currently ~16MB, but may change.

Source

pub fn http2_max_pending_accept_reset_streams( &mut self, max: impl Into<Option<usize>>, ) -> &mut Self

Configures the maximum number of pending reset streams allowed before a GOAWAY will be sent.

This will default to the default value set by the h2 crate. As of v0.3.17, it is 20.

See https://github.com/hyperium/hyper/issues/2877 for more information.

Source

pub fn http2_max_send_buf_size(&mut self, max: usize) -> &mut Self

Set the maximum write buffer size for each HTTP/2 stream.

Default is currently ~400KB, but may change.

§Panics

The value must be no larger than u32::MAX.

Source

pub fn http2_keep_alive_interval( &mut self, interval: impl Into<Option<Duration>>, ) -> &mut Self

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.

Source

pub fn http2_keep_alive_timeout(&mut self, timeout: Duration) -> &mut Self

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 20 seconds.

Source

pub fn max_buf_size(&mut self, max: usize) -> &mut Self

Set the maximum buffer size for the HTTP/1 connection.

Default is ~400kb.

§Panics

The minimum value allowed is 8192. This method panics if the passed max is less than the minimum.

Examples found in repository?
examples/configure_http.rs (line 16)
10async fn main() {
11    let app = Router::new().route("/", get(|| async { "Hello, world!" }));
12
13    let config = HttpConfig::new()
14        .http1_only(true)
15        .http2_only(false)
16        .max_buf_size(8192)
17        .build();
18
19    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
20    println!("listening on {}", addr);
21    hyper_server::bind(addr)
22        .http_config(config)
23        .serve(app.into_make_service())
24        .await
25        .unwrap();
26}
Source

pub fn pipeline_flush(&mut self, enabled: bool) -> &mut Self

Determines if multiple responses should be buffered and sent together to support pipelined responses.

This can improve throughput in certain situations, but is experimental and might contain issues.

Default is false.

Trait Implementations§

Source§

impl Clone for HttpConfig

Source§

fn clone(&self) -> HttpConfig

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HttpConfig

Source§

fn default() -> Self

Provides a default HTTP configuration.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more