1
0
mirror of https://github.com/actix/actix-website synced 2024-12-18 09:53:12 +01:00
actix-website/content/docs/http2.md
2018-05-22 23:15:08 +02:00

1.6 KiB

title menu weight
HTTP/2.0 docs_proto 250

actix-web automatically upgrades connections to HTTP/2.0 if possible.

Negotiation

HTTP/2.0 protocol over tls without prior knowledge requires tls alpn.

Currently, only rust-openssl has support.

alpn negotiation requires enabling the feature. When enabled, HttpServer provides the serve_tls method.

[dependencies]
actix-web = { version = "{{< actix-version "actix-web" >}}", features = ["alpn"] }
openssl = { version = "0.10", features = ["v110"] }
use std::fs::File;
use actix_web::*;
use openssl::ssl::{SslMethod, SslAcceptor, SslFiletype};

fn main() {
    // load ssl keys
    let mut builder = SslAcceptor::mozilla_intermediate(SslMethod::tls()).unwrap();
    builder.set_private_key_file("key.pem", SslFiletype::PEM).unwrap();
    builder.set_certificate_chain_file("cert.pem").unwrap();

    HttpServer::new(
        || App::new()
            .resource("/index.html", |r| r.f(index)))
        .bind("127.0.0.1:8080").unwrap();
        .serve_ssl(builder).unwrap();
}

Upgrades to HTTP/2.0 schema described in rfc section 3.2 is not supported. Starting HTTP/2 with prior knowledge is supported for both clear text connection and tls connection. rfc section 3.4

Check out examples/tls for a concrete example.