Crate hyper_server

Source
Expand description

hyper-server is a hyper server implementation designed to be used with axum framework.

§Features

  • HTTP/1 and HTTP/2
  • HTTPS through rustls or openssl.
  • High performance through hyper.
  • Using tower make service API.
  • Very good axum compatibility. Likely to work with future axum releases.
  • Proxy protocol support for use behind network load balancers.

§Guide

hyper-server can serve items that implement MakeService with some additional trait bounds. Make services that are created using axum complies with those trait bounds out of the box. Therefore it is more convenient to use this crate with axum.

All examples in this crate uses axum. If you want to use this crate without axum it is highly recommended to learn how tower works.

Server::bind or bind function can be called to create a server that will bind to provided SocketAddr when serve is called.

A Handle can be passed to Server for additional utilities like shutdown and graceful shutdown.

bind_rustls can be called by providing RustlsConfig to create a HTTPS Server that will bind on provided SocketAddr. RustlsConfig can be cloned, reload methods can be used on clone to reload tls configuration.

§Features

  • tls-rustls - activate rustls support.
  • tls-openssl - activate openssl support.

§Example

A simple hello world application can be served like:

use axum::{routing::get, Router};
use std::net::SocketAddr;

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(|| async { "Hello, world!" }));

    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    println!("listening on {}", addr);
    hyper_server::bind(addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

You can find more examples in repository.

Modules§

accept
Module accept provides utilities for asynchronously processing and modifying IO streams and services.
proxy_protocolproxy_protocol
This feature allows the hyper_server to be used behind a layer 4 load balancer whilst the proxy protocol is enabled to preserve the client IP address and port. See The PROXY protocol spec for more details: https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt.
service
Module containing service traits. These traits are vital for handling requests and creating services within the server.
tls_openssltls-openssl
Tls implementation using openssl
tls_rustlstls-rustls
Tls implementation using rustls.

Structs§

AddrIncomingConfig
Configuration settings for the AddrIncoming.
Handle
A handle to manage and interact with the server.
HttpConfig
Represents a configuration for the Http protocol. This allows for detailed customization of various HTTP/1 and HTTP/2 settings.
Server
Represents an HTTP server with customization capabilities for handling incoming requests.

Functions§

bind
Creates a new Server instance that binds to the provided address.
bind_openssltls-openssl
Binds a TLS server using OpenSSL to the specified address with the given configuration.
bind_rustlstls-rustls
Creates a TLS server that binds to the provided address using the rustls library.
from_tcp
Creates a new Server instance using an existing std::net::TcpListener.
from_tcp_rustlstls-rustls
Creates a TLS server from an existing std::net::TcpListener using the rustls library.