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

1.5 KiB
Raw Blame History

title menu weight
HTTP/2.0 docs_proto 250

如果可能actix-web自动升级到HTTP/2.0的连接。

协议

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

目前,只有rust-openssl支持

alpn协议需要启用该功能。启用后HttpServer提供 serve_tls方法。 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();
}

不支持升级到rfc section 3.2 节中描述的HTTP/2.0模式 。明文连接和tls连接都支持HTTP/2 with prior knowledge启动,rfc section 3.4

查看具体示例examples/tls.