Trait fibers_http_server::HandleRequest
[−]
[src]
pub trait HandleRequest: Sized + Send + Sync + 'static { type ReqBody: Send + 'static; type ResBody: Send + 'static; type Decoder: BodyDecode<Item = Self::ReqBody> + Send + 'static; type Encoder: BodyEncode<Item = Self::ResBody> + Send + 'static; type Reply: Future<Item = Res<Self::ResBody>, Error = Never> + Send + 'static; const METHOD: &'static str; const PATH: &'static str; fn handle_request(&self, req: Req<Self::ReqBody>) -> Self::Reply; fn handle_request_head(&self, req: &Req<()>) -> Option<Res<Self::ResBody>> { ... } fn handle_decoding_error(
&self,
req: Req<()>,
error: &Error
) -> Option<Res<Self::ResBody>> { ... } }
HandleRequest
allows for handling HTTP requests.
Associated Types
type ReqBody: Send + 'static
The type of the request bodies.
type ResBody: Send + 'static
The type of the response bodies.
type Decoder: BodyDecode<Item = Self::ReqBody> + Send + 'static
Request body decoder.
type Encoder: BodyEncode<Item = Self::ResBody> + Send + 'static
Response body encoder.
type Reply: Future<Item = Res<Self::ResBody>, Error = Never> + Send + 'static
Future
that represents reply to a request.
Associated Constants
const METHOD: &'static str
The method that the handler can handle.
const PATH: &'static str
The request path that the handler can handle.
*
and **
in the path have the special meanings as follows:
*
matches any path segment (i.e., regarded as a wildcard)**
matches all remaining parts of a path
Required Methods
fn handle_request(&self, req: Req<Self::ReqBody>) -> Self::Reply
Handles a request.
Provided Methods
fn handle_request_head(&self, req: &Req<()>) -> Option<Res<Self::ResBody>>
Handles the head part of a request.
If a Some(..)
value is returned, the invocation of handle_request
method will be skipped.
The default implementation always returns None
.
fn handle_decoding_error(
&self,
req: Req<()>,
error: &Error
) -> Option<Res<Self::ResBody>>
&self,
req: Req<()>,
error: &Error
) -> Option<Res<Self::ResBody>>
Handles an error occurred while decoding the body of a request.
The default implementation always returns None
(i.e., the default error response will be returned to the HTTP client).
Implementors
impl HandleRequest for MetricsHandler type ReqBody = (); type ResBody = String; type Decoder = BodyDecoder<NullDecoder>; type Encoder = BodyEncoder<Utf8Encoder>; type Reply = Finished<Res<Self::ResBody>, Never>;
impl<H: HandleRequest> HandleRequest for WithMetrics<H> type ReqBody = H::ReqBody; type ResBody = H::ResBody; type Decoder = H::Decoder; type Encoder = H::Encoder; type Reply = Time<H>;