pub struct HttpService<F, Req: RequestState<Io<F>>, Err> { /* private fields */ }Expand description
An HTTP/1.1 and HTTP/2 transport service.
The protocol is selected from
HttpProtocol metadata attached to the I/O
stream, normally by a TLS ALPN acceptor. Connections without HTTP/2
metadata are handled as HTTP/1.
§Factory scope
The application and control service factories are instantiated once per
accepted connection: ServiceFactory::create runs for every connection
and the resulting services are dropped when it closes. Do not perform
expensive initialization or keep state that must outlive a connection in
these factories. Build such state once per worker instead, for example in
the server factory closure that constructs this HttpService (or the
web::HttpServer application closure), or in the worker state passed to
create, and share it by cloning an Rc or Arc into the factory.
Implementations§
Source§impl<F, Req, Err> HttpService<F, Req, Err>where
F: Filter + 'static,
Req: RequestState<Io<F>>,
Req::State: Clone,
Err: ResponseError + 'static,
impl<F, Req, Err> HttpService<F, Req, Err>where
F: Filter + 'static,
Req: RequestState<Io<F>>,
Req::State: Clone,
Err: ResponseError + 'static,
Sourcepub fn new<H>(sf: impl IntoServiceFactory<H, Req::State, Request>) -> Selfwhere
H: ServiceFactory<Req::State, Request, Error = Err> + 'static,
H::Res: Into<Response>,
H::InitError: IntoFailure,
pub fn new<H>(sf: impl IntoServiceFactory<H, Req::State, Request>) -> Selfwhere
H: ServiceFactory<Req::State, Request, Error = Err> + 'static,
H::Res: Into<Response>,
H::InitError: IntoFailure,
Creates a service that supports HTTP/1.1 and HTTP/2.
sf is instantiated for every accepted connection; see
factory scope.
Sourcepub fn h1<H>(
sf: impl IntoServiceFactory<H, Req::State, Request>,
) -> H1Service<F, Req, Err>where
H: ServiceFactory<Req::State, Request, Error = Err> + 'static,
H::Res: Into<Response>,
H::InitError: IntoFailure,
pub fn h1<H>(
sf: impl IntoServiceFactory<H, Req::State, Request>,
) -> H1Service<F, Req, Err>where
H: ServiceFactory<Req::State, Request, Error = Err> + 'static,
H::Res: Into<Response>,
H::InitError: IntoFailure,
Creates an HTTP/1-only service.
sf is instantiated for every accepted connection; see
factory scope.
Sourcepub fn h2<H>(
sf: impl IntoServiceFactory<H, Req::State, Request>,
) -> H2Service<F, Req, Err>where
H: ServiceFactory<Req::State, Request, Error = Err> + 'static,
H::Res: Into<Response>,
H::InitError: IntoFailure,
pub fn h2<H>(
sf: impl IntoServiceFactory<H, Req::State, Request>,
) -> H2Service<F, Req, Err>where
H: ServiceFactory<Req::State, Request, Error = Err> + 'static,
H::Res: Into<Response>,
H::InitError: IntoFailure,
Creates an HTTP/2-only service.
sf is instantiated for every accepted connection; see
factory scope.
Source§impl<F, Req, Err> HttpService<F, Req, Err>
impl<F, Req, Err> HttpService<F, Req, Err>
Sourcepub fn h1_control<Ctl>(
self,
ctl: impl IntoServiceFactory<Ctl, Req::State, Control<F, Err>>,
) -> Selfwhere
Ctl: ServiceFactory<Req::State, Control<F, Err>, Res = ControlAck<F>> + 'static,
Ctl::Error: IntoFailure,
Ctl::InitError: IntoFailure,
pub fn h1_control<Ctl>(
self,
ctl: impl IntoServiceFactory<Ctl, Req::State, Control<F, Err>>,
) -> Selfwhere
Ctl: ServiceFactory<Req::State, Control<F, Err>, Res = ControlAck<F>> + 'static,
Ctl::Error: IntoFailure,
Ctl::InitError: IntoFailure,
Provides the HTTP/1 control service.
The service receives the lifecycle events described by
h1::Control. Unless this method is called, the default action is
applied to each event without a service call. Like the application
factory, ctl is instantiated for every HTTP/1 connection.
Sourcepub fn h2_control<Ctl>(
self,
ctl: impl IntoServiceFactory<Ctl, Req::State, Control<Error<H2Error>>>,
) -> Selfwhere
Ctl: ServiceFactory<Req::State, Control<Error<H2Error>>, Res = ControlAck> + 'static,
Ctl::Error: IntoFailure,
Ctl::InitError: IntoFailure,
pub fn h2_control<Ctl>(
self,
ctl: impl IntoServiceFactory<Ctl, Req::State, Control<Error<H2Error>>>,
) -> Selfwhere
Ctl: ServiceFactory<Req::State, Control<Error<H2Error>>, Res = ControlAck> + 'static,
Ctl::Error: IntoFailure,
Ctl::InitError: IntoFailure,
Provides the HTTP/2 control service.
Unless this method is called, the default action is applied to each
HTTP/2 control event without a service call. Like the application
factory, ctl is instantiated for every HTTP/2 connection.