Struct HttpServer

Source
pub struct HttpServer<S, const HEADER_LIMIT: usize = DEFAULT_HEADER_LIMIT, const READ_BUF_LIMIT: usize = DEFAULT_READ_BUF_LIMIT, const WRITE_BUF_LIMIT: usize = DEFAULT_WRITE_BUF_LIMIT> { /* private fields */ }
Expand description

multi protocol handling http server

Implementations§

Source§

impl<S> HttpServer<S>
where S: Send + Sync + 'static,

Source

pub fn serve(service: S) -> Self

Source§

impl<S, const HEADER_LIMIT: usize, const READ_BUF_LIMIT: usize, const WRITE_BUF_LIMIT: usize> HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>
where S: Send + Sync + 'static,

Source

pub fn server_threads(self, num: usize) -> Self

Set number of threads dedicated to accepting connections.

Default set to 1.

§Panics:

When receive 0 as number of server thread.

Source

pub fn worker_threads(self, num: usize) -> Self

Set number of workers to start.

Default set to available logical cpu as workers count.

§Panics:

When received 0 as number of worker thread.

Source

pub fn worker_max_blocking_threads(self, num: usize) -> Self

Set max number of threads for each worker’s blocking task thread pool.

One thread pool is set up per worker; not shared across workers.

Source

pub fn disable_signal(self) -> Self

Disable signal listening.

tokio::signal is used for listening and it only functions in tokio runtime 1.x. Disabling it would enable server runs in other async runtimes.

Source

pub fn backlog(self, num: u32) -> Self

Source

pub fn disable_vectored_write(self) -> Self

Disable vectored write even when IO is able to perform it.

This is beneficial when dealing with small size of response body.

Source

pub fn keep_alive_timeout(self, dur: Duration) -> Self

Change keep alive duration for Http/1 connection.

Connection kept idle for this duration would be closed.

Source

pub fn request_head_timeout(self, dur: Duration) -> Self

Change request timeout for Http/1 connection.

Connection can not finish it’s request for this duration would be closed.

This timeout is also used in Http/2 connection handshake phrase.

Source

pub fn tls_accept_timeout(self, dur: Duration) -> Self

Change tls accept timeout for Http/1 and Http/2 connection.

Connection can not finish tls handshake for this duration would be closed.

Source

pub fn max_read_buf_size<const READ_BUF_LIMIT_2: usize>( self, ) -> HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT_2, WRITE_BUF_LIMIT>

Change max size for request head.

Request has a bigger head than it would be reject with error. Request body has a bigger continuous read would be force to yield.

Default to 1mb.

Source

pub fn max_write_buf_size<const WRITE_BUF_LIMIT_2: usize>( self, ) -> HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT_2>

Change max size for write buffer size.

When write buffer hit limit it would force a drain write to Io stream until it’s empty (or connection closed by error or remote peer).

Default to 408kb.

Source

pub fn max_request_headers<const HEADER_LIMIT_2: usize>( self, ) -> HttpServer<S, HEADER_LIMIT_2, READ_BUF_LIMIT, WRITE_BUF_LIMIT>

Change max header fields for one request.

Default to 64.

Source

pub fn bind<A, ResB, BE>(self, addr: A) -> Result<Self>
where A: ToSocketAddrs, S: Service + 'static, S::Response: ReadyService + Service<Request<RequestExt<RequestBody>>, Response = Response<ResB>> + 'static, S::Error: Debug, <S::Response as Service<Request<RequestExt<RequestBody>>>>::Error: Debug, ResB: Stream<Item = Result<Bytes, BE>> + 'static, BE: Debug + 'static,

Source

pub fn listen<ResB, BE, L>(self, listener: L) -> Result<Self>
where S: Service + 'static, S::Response: ReadyService + Service<Request<RequestExt<RequestBody>>, Response = Response<ResB>> + 'static, S::Error: Debug, <S::Response as Service<Request<RequestExt<RequestBody>>>>::Error: Debug, ResB: Stream<Item = Result<Bytes, BE>> + 'static, BE: Debug + 'static, L: IntoListener + 'static,

Source

pub fn bind_openssl<A: ToSocketAddrs, ResB, BE>( self, addr: A, builder: SslAcceptorBuilder, ) -> Result<Self>
where S: Service + 'static, S::Response: ReadyService + Service<Request<RequestExt<RequestBody>>, Response = Response<ResB>> + 'static, S::Error: Debug, <S::Response as Service<Request<RequestExt<RequestBody>>>>::Error: Debug, ResB: Stream<Item = Result<Bytes, BE>> + 'static, BE: Debug + 'static,

Source

pub fn bind_rustls<A: ToSocketAddrs, ResB, BE>( self, addr: A, config: ServerConfig, ) -> Result<Self>
where S: Service + 'static, S::Response: ReadyService + Service<Request<RequestExt<RequestBody>>, Response = Response<ResB>> + 'static, S::Error: Debug, <S::Response as Service<Request<RequestExt<RequestBody>>>>::Error: Debug, ResB: Stream<Item = Result<Bytes, BE>> + 'static, BE: Debug + 'static,

Source

pub fn bind_unix<P: AsRef<Path>, ResB, BE>(self, path: P) -> Result<Self>
where S: Service + 'static, S::Response: ReadyService + Service<Request<RequestExt<RequestBody>>, Response = Response<ResB>> + 'static, S::Error: Debug, <S::Response as Service<Request<RequestExt<RequestBody>>>>::Error: Debug, ResB: Stream<Item = Result<Bytes, BE>> + 'static, BE: Debug + 'static,

Source

pub fn bind_h3<A: ToSocketAddrs, ResB, BE>( self, addr: A, config: QuicConfig, ) -> Result<Self>
where S: Service + 'static, S::Response: ReadyService + Service<Request<RequestExt<RequestBody>>, Response = Response<ResB>> + 'static, S::Error: Debug, <S::Response as Service<Request<RequestExt<RequestBody>>>>::Error: Debug, ResB: Stream<Item = Result<Bytes, BE>> + 'static, BE: Debug + 'static,

Source

pub fn run(self) -> ServerFuture

Auto Trait Implementations§

§

impl<S, const HEADER_LIMIT: usize, const READ_BUF_LIMIT: usize, const WRITE_BUF_LIMIT: usize> Freeze for HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>

§

impl<S, const HEADER_LIMIT: usize = DEFAULT_HEADER_LIMIT, const READ_BUF_LIMIT: usize = DEFAULT_READ_BUF_LIMIT, const WRITE_BUF_LIMIT: usize = DEFAULT_WRITE_BUF_LIMIT> !RefUnwindSafe for HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>

§

impl<S, const HEADER_LIMIT: usize, const READ_BUF_LIMIT: usize, const WRITE_BUF_LIMIT: usize> Send for HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>
where S: Sync + Send,

§

impl<S, const HEADER_LIMIT: usize = DEFAULT_HEADER_LIMIT, const READ_BUF_LIMIT: usize = DEFAULT_READ_BUF_LIMIT, const WRITE_BUF_LIMIT: usize = DEFAULT_WRITE_BUF_LIMIT> !Sync for HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>

§

impl<S, const HEADER_LIMIT: usize, const READ_BUF_LIMIT: usize, const WRITE_BUF_LIMIT: usize> Unpin for HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>

§

impl<S, const HEADER_LIMIT: usize = DEFAULT_HEADER_LIMIT, const READ_BUF_LIMIT: usize = DEFAULT_READ_BUF_LIMIT, const WRITE_BUF_LIMIT: usize = DEFAULT_WRITE_BUF_LIMIT> !UnwindSafe for HttpServer<S, HEADER_LIMIT, READ_BUF_LIMIT, WRITE_BUF_LIMIT>

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> BorrowState<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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