#hyper-server #hyper #web-server #server #openssl #web

simple-hyper-server-tls

Simplify TLS configuration for Hyper server

8 releases

0.3.2 Jun 22, 2022
0.3.1 Jun 13, 2022
0.2.0 May 31, 2022
0.1.4 May 31, 2022

#23 in #hyper-server

Download history 174/week @ 2024-07-20 129/week @ 2024-07-27 200/week @ 2024-08-03 168/week @ 2024-08-10 66/week @ 2024-08-17 18/week @ 2024-08-24 19/week @ 2024-08-31 35/week @ 2024-09-07 36/week @ 2024-09-14 46/week @ 2024-09-21 112/week @ 2024-09-28 36/week @ 2024-10-05 16/week @ 2024-10-12 65/week @ 2024-10-19 11/week @ 2024-10-26 102/week @ 2024-11-02

197 downloads per month

LGPL-2.1-or-later

27KB
242 lines

Simple Hyper Server TLS

LGPL 2.1 License Crate version Docs

The library to simplify TLS configuration for Hyper server including ALPN (Application-Layer Protocol Negotiation) setup. This library setup TLS configuration suitable for clients. The configuration includes the HTTP protocol choice setup (ALPN mechanism setup) thanks to the almost clients can choose for example HTTP/2 protocol.

The usage of this library requires choose suitable the TLS implementation, by choosing feature that one of:

  • tls-rustls - RusTLS - native for Rust TLS implementation based on tokio-rustls,
  • tls-openssl - OpenSSL - TLS implementation based native OpenSSL library and openssl.

The tls-openssl is recommended for systems which can not handle rustls due to some problems, like lacks of some CPU instructions needed by ring crate. For other systems, tls-rustls should be preferred.

By default three versions of HTTP protocol are enabled (HTTP/1.0, HTTP/1.1, HTTP/2). It is possible to choose only one version by disabling default features and choose one of features:

  • hyper-h1 - for HTTP/1.0 or HTTP/1.1,
  • hyper-h2 - for HTTP/2.

List of other features

  • hyper-full-server - enables all features for hyper server.

Examples

The simplest usage is:

use std::{convert::Infallible, net::SocketAddr};
use simple_hyper_server_tls::*;
use hyper::{Body, Request, Response, Server};
use hyper::service::{make_service_fn, service_fn};

async fn handle(_: Request<Body>) -> Result<Response<Body>, Infallible> {
    Ok(Response::new("Hello, World!".into()))
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));

    let make_svc = make_service_fn(|_conn| async {
        Ok::<_, Infallible>(service_fn(handle))
    });
    let mut server = hyper_from_pem_files("cert.pem", "key.pem", Protocols::ALL, &addr)?
            .serve(make_svc);
    while let Err(e) = (&mut server).await {
        eprintln!("server error: {}", e);
    }
    Ok(())
}

Additional functions can be used for customization of the TLS configuration.

Dependencies

~5–16MB
~217K SLoC