From d03d1207a8ed7c43d53ccd0a3501fd6915945d69 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 2 Dec 2017 00:36:50 -0800 Subject: [PATCH] add http2 section --- guide/src/SUMMARY.md | 1 + guide/src/qs_13.md | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 guide/src/qs_13.md diff --git a/guide/src/SUMMARY.md b/guide/src/SUMMARY.md index 5c3b165bb..93a265a42 100644 --- a/guide/src/SUMMARY.md +++ b/guide/src/SUMMARY.md @@ -12,3 +12,4 @@ - [User sessions](./qs_10.md) - [Logging](./qs_11.md) - [Static file handling](./qs_12.md) +- [HTTP/2](./qs_13.md) diff --git a/guide/src/qs_13.md b/guide/src/qs_13.md new file mode 100644 index 000000000..5a2472d4d --- /dev/null +++ b/guide/src/qs_13.md @@ -0,0 +1,41 @@ +# HTTP/2 + +Actix web automatically upgrades connection to `http/2` if possible. + +## Negotiation + +`HTTP/2` protocol over tls without prior knowlage requires +[tls alpn](https://tools.ietf.org/html/rfc7301). At the moment only +`rust-openssl` has support. Turn on `alpn` feature to enable `alpn` negotiation. +With enable `alpn` feature `HttpServer` provides +[serve_tls](../actix_web/struct.HttpServer.html#method.serve_tls) method. + +```toml +[dependencies] +actix-web = { git = "https://github.com/actix/actix-web", features=["alpn"] } +``` + +```rust,ignore +use std::fs::File; +use actix_web::*; + +fn main() { + let mut file = File::open("identity.pfx").unwrap(); + let mut pkcs12 = vec![]; + file.read_to_end(&mut pkcs12).unwrap(); + let pkcs12 = Pkcs12::from_der(&pkcs12).unwrap().parse("12345").unwrap(); + + HttpServer::new( + Application::default("/") + .handler("/index.html", index) + .serve_tls::<_, ()>("127.0.0.1:8080", pkcs12).unwrap(); +} +``` + +Upgrade to `http/2` schema described in +[rfc section 3.2](https://http2.github.io/http2-spec/#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](https://http2.github.io/http2-spec/#rfc.section.3.4) + +Please check [example](https://github.com/actix/actix-web/tree/master/examples/tls) +for concrete example.