Module hyperdriver::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: hyperdriver::body::Request) -> Result<hyperdriver::body::Response, BoxError> {
    Ok(hyperdriver::body::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));

    server.await.unwrap();
}

Re-exports§

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

Modules§

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

Structs§

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

Enums§

  • An error that can occur when serving connections.

Traits§

  • A transport protocol for serving connections.