Struct Builder
pub struct Builder { /* private fields */ }
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(&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(&mut self, val: bool) -> &mut SelfEnables or disables HTTP/1 keep-alive.
Default is
true.fn title_case_headers(&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 allow_multiple_spaces_in_request_line_delimiters(&mut self, enabled: bool) -> &mut SelfSet whether multiple spaces are allowed as delimiters in request lines.
Default is
false.fn ignore_invalid_headers(&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(&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(&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(&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(&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 use.fn max_buf_size(&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(&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(&mut self, enabled: bool) -> &mut SelfAggregates flushes to better support pipelined responses.
Experimental, may have bugs.
Default is
false.fn timer<M>(&mut self, timer: M) -> &mut Self where M: Timer + Send + Sync + 'static,Set the timer used in background tasks.
fn serve_connection<I, S>(&self, io: I, service: S) -> Connection<I, S> where S: HttpService<IncomingBody>, S::Error: Into<Box<dyn StdError + Send + Sync>>, S::ResBody: 'static, <S::ResBody as Body>::Error: Into<Box<dyn StdError + Send + Sync>>, I: Read + Write + Unpin,Bind 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, # #
Trait Implementations
impl Clone for Builder
fn clone(&self) -> Builder
impl Debug for Builder
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl !RefUnwindSafe for Builder
impl !UnwindSafe for Builder
impl Freeze for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
Blanket Implementations
impl<T> Any for Builder
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Builder
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Builder
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Builder
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Builder
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for Builder
impl<T> ToOwned for Builder
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T> WithSubscriber for Builder
impl<T, U> Into<U> for Builder
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Builder
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Builder
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>