[][src]Trait http_service::HttpService

pub trait HttpService: Send + Sync + 'static {
    type Connection: Send + 'static;
    type ConnectionFuture: Send + 'static + TryFuture<Ok = Self::Connection>;
    type ResponseFuture: Send + 'static + TryFuture<Ok = Response>;
    fn connect(&self) -> Self::ConnectionFuture;
fn respond(
        &self,
        conn: &mut Self::Connection,
        req: Request
    ) -> Self::ResponseFuture; }

An async HTTP service

An instance represents a service as a whole. The associated Conn type represents a particular connection, and may carry connection-specific state.

Associated Types

type Connection: Send + 'static

An individual connection.

This associated type is used to establish and hold any per-connection state needed by the service.

type ConnectionFuture: Send + 'static + TryFuture<Ok = Self::Connection>

A future for setting up an individual connection.

This method is called each time the server receives a new connection request, but before actually exchanging any data with the client.

Returning an error will result in the server immediately dropping the connection.

type ResponseFuture: Send + 'static + TryFuture<Ok = Response>

The async computation for producing the response.

Returning an error will result in the server immediately dropping the connection. It is usually preferable to instead return an HTTP response with an error status code.

Loading content...

Required methods

fn connect(&self) -> Self::ConnectionFuture

Initiate a new connection.

This method is given access to the global service (&self), which may provide handles to connection pools, thread pools, or other global data.

fn respond(
    &self,
    conn: &mut Self::Connection,
    req: Request
) -> Self::ResponseFuture

Begin handling a single request.

The handler is given shared access to the service itself, and mutable access to the state for the connection where the request is taking place.

Loading content...

Implementors

Loading content...