Trait HandleRequest

Source
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;

    // Required method
    fn handle_request(&self, req: Req<Self::ReqBody>) -> Self::Reply;

    // Provided methods
    fn handle_request_head(&self, req: &Req<()>) -> Option<Res<Self::ResBody>> { ... }
    fn handle_decoding_error(
        &self,
        req: Req<()>,
        error: &Error,
    ) -> Option<Res<Self::ResBody>> { ... }
}
Expand description

HandleRequest allows for handling HTTP requests.

Required Associated Constants§

Source

const METHOD: &'static str

The method that the handler can handle.

Source

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 Associated Types§

Source

type ReqBody: Send + 'static

The type of the request bodies.

Source

type ResBody: Send + 'static

The type of the response bodies.

Source

type Decoder: BodyDecode<Item = Self::ReqBody> + Send + 'static

Request body decoder.

Source

type Encoder: BodyEncode<Item = Self::ResBody> + Send + 'static

Response body encoder.

Source

type Reply: Future<Item = Res<Self::ResBody>, Error = Never> + Send + 'static

Future that represents reply to a request.

Required Methods§

Source

fn handle_request(&self, req: Req<Self::ReqBody>) -> Self::Reply

Handles a request.

Provided Methods§

Source

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.

Source

fn handle_decoding_error( &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).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§