Module server

Source
Available on crate feature server only.
Expand description

A server framework with connection management, automatic HTTP/1.1 and HTTP/2 switching, and pluggable acceptors, protocols, and services.

§Overview

Server is the primary entry point for this module, and represents the components which are ready to serve requests. It has a builder API for confiugration, Server::builder and can be await-ed to start serving connections.

When a new connection arrives, it is the acceptor’s job to accept the connection and provide a bi-directional stream of bytes. The server then uses the protocol to determine how to handle that connection and serve requests. A service is used to handle individual requests. The service is generated by the “MakeService” which is provided by the user.

A “MakeService” is a service which creates services, aka a service factory. The service factory will recieve a reference to the underlying connection stream.

§Low Level Components

The conn module contains the low-level components that are used to build a server, including the built in acceptors and protocols. These can be used to build custom servers with different behavior, or to extend the built-in server with custom acceptors or protocols.

§Example


async fn echo(req: http::Request<Body>) -> Result<http::Response<Body>, BoxError> {
    Ok(http::Response::new(req.into_body()))
}

async fn example_server() {
    let (client, incoming) = hyperdriver::stream::duplex::pair();

   let server = hyperdriver::server::Server::builder()
    .with_incoming(incoming)
    .with_http1()
    .with_shared_service(tower::service_fn(echo))
    .with_tokio();

    server.await.unwrap();
}

Re-exports§

pub use self::conn::auto::Builder as AutoBuilder;
pub use self::conn::Accept;

Modules§

conn
Server-side connection builders for the HTTP2 protocol and the HTTP1 protocol.

Structs§

GracefulShutdown
A server that can accept connections, and run each connection, and can also process graceful shutdown signals.
Server
A server that can accept connections, and run each connection using a tower::Service.
Serving
A future that drives the server to accept connections.

Enums§

ServerError
An error that can occur when serving connections.

Traits§

GracefulServerExecutor
An executor suitable for spawning connection futures and driving them to completion.
Protocol
A transport protocol for serving connections.
ServerExecutor
An executor suitable for spawning connection futures and driving them to completion.