Struct Builder
struct Builder { ... }
A configuration builder for HTTP/1 server connections.
Note: The default values of options are not considered stable. They are subject to change at any time.
Example
# use Duration;
# use Builder;
#
Use Builder::serve_connection
to bind the built connection to a service.
Implementations
impl Builder
fn new() -> SelfCreate a new connection builder.
fn half_close(self: &mut Self, val: bool) -> &mut SelfSet whether HTTP/1 connections should support half-closures.
Clients can chose to shutdown their write-side while waiting for the server to respond. Setting this to
truewill prevent closing the connection immediately ifreaddetects an EOF in the middle of a request.Default is
false.fn keep_alive(self: &mut Self, val: bool) -> &mut SelfEnables or disables HTTP/1 keep-alive.
Default is true.
fn title_case_headers(self: &mut Self, enabled: bool) -> &mut SelfSet whether HTTP/1 connections will write header names as title case at the socket level.
Default is false.
fn ignore_invalid_headers(self: &mut Self, enabled: bool) -> &mut BuilderSet whether HTTP/1 connections will silently ignored malformed header lines.
If this is enabled and a header line does not start with a valid header name, or does not include a colon at all, the line will be silently ignored and no error will be reported.
Default is false.
fn preserve_header_case(self: &mut Self, enabled: 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
Request. It will also look for and use such an extension in any providedResponse.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.
Default is false.
fn max_headers(self: &mut Self, val: usize) -> &mut SelfSet the maximum number of headers.
When a request is received, the parser will reserve a buffer to store headers for optimal performance.
If server receives more headers than the buffer size, it responds to the client with "431 Request Header Fields Too Large".
Note that 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 request, and there will be a performance drop of about 5%.
Default is 100.
fn header_read_timeout<impl Into<Option<Duration>>: Into<Option<Duration>>>(self: &mut Self, read_timeout: impl Into<Option<Duration>>) -> &mut SelfSet a timeout for reading client request headers. If a client does not transmit the entire header within this time, the connection is closed.
Requires a
Timerset byBuilder::timerto take effect. Panics ifheader_read_timeoutis configured without aTimer.Pass
Noneto disable.Default is 30 seconds.
fn writev(self: &mut Self, val: bool) -> &mut SelfSet 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 max_buf_size(self: &mut Self, max: usize) -> &mut SelfSet the maximum buffer size for the connection.
Default is ~400kb.
Panics
The minimum value allowed is 8192. This method panics if the passed
maxis less than the minimum.fn auto_date_header(self: &mut Self, enabled: bool) -> &mut SelfSet whether the
dateheader should be included in HTTP responses.Note that including the
dateheader is recommended by RFC 7231.Default is true.
fn pipeline_flush(self: &mut Self, enabled: bool) -> &mut SelfAggregates flushes to better support pipelined responses.
Experimental, may have bugs.
Default is false.
fn timer<M>(self: &mut Self, timer: M) -> &mut Self where M: Timer + Send + Sync + 'staticSet the timer used in background tasks.
fn serve_connection<I, S>(self: &Self, io: I, service: S) -> Connection<I, S> where S: HttpService<IncomingBody>, <S as >::Error: Into<Box<dyn StdError + Send + Sync>>, <S as >::ResBody: 'static, <<S as >::ResBody as Body>::Error: Into<Box<dyn StdError + Send + Sync>>, I: Read + Write + UnpinBind a connection together with a
Service.This returns a Future that must be polled in order for HTTP to be driven on the connection.
Panics
If a timeout option has been configured, but a
timerhas not been provided, callingserve_connectionwill panic.Example
# use ; # use Service; # use Builder; # use ; # async # where # I: Read + Write + Unpin + Send + 'static, # S: + Send + 'static, # Error: , # Future: Send, # #
impl Clone for Builder
fn clone(self: &Self) -> Builder
impl Debug for Builder
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin 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>