2017-12-14 07:36:28 +01:00
|
|
|
# HTTP/2.0
|
2017-12-02 09:36:50 +01:00
|
|
|
|
2017-12-14 07:36:28 +01:00
|
|
|
Actix web automatically upgrades connection to *HTTP/2.0* if possible.
|
2017-12-02 09:36:50 +01:00
|
|
|
|
|
|
|
## Negotiation
|
|
|
|
|
2018-01-13 20:17:48 +01:00
|
|
|
*HTTP/2.0* protocol over tls without prior knowledge requires
|
2017-12-02 09:36:50 +01:00
|
|
|
[tls alpn](https://tools.ietf.org/html/rfc7301). At the moment only
|
2018-03-28 22:16:01 +02:00
|
|
|
`rust-openssl` has support. Turn on the `alpn` feature to enable `alpn` negotiation.
|
|
|
|
With enabled `alpn` feature `HttpServer` provides the
|
2017-12-02 09:36:50 +01:00
|
|
|
[serve_tls](../actix_web/struct.HttpServer.html#method.serve_tls) method.
|
|
|
|
|
|
|
|
```toml
|
|
|
|
[dependencies]
|
2018-01-25 19:24:04 +01:00
|
|
|
actix-web = { version = "0.3.3", features=["alpn"] }
|
|
|
|
openssl = { version="0.10", features = ["v110"] }
|
2017-12-02 09:36:50 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
```rust,ignore
|
|
|
|
use std::fs::File;
|
|
|
|
use actix_web::*;
|
2018-01-25 19:24:04 +01:00
|
|
|
use openssl::ssl::{SslMethod, SslAcceptor, SslFiletype};
|
2017-12-02 09:36:50 +01:00
|
|
|
|
|
|
|
fn main() {
|
2018-01-25 19:24:04 +01:00
|
|
|
// 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();
|
2017-12-02 09:36:50 +01:00
|
|
|
|
|
|
|
HttpServer::new(
|
2017-12-14 06:56:30 +01:00
|
|
|
|| Application::new()
|
|
|
|
.resource("/index.html", |r| r.f(index)))
|
2017-12-20 03:36:29 +01:00
|
|
|
.bind("127.0.0.1:8080").unwrap();
|
2018-01-25 19:24:04 +01:00
|
|
|
.serve_ssl(builder).unwrap();
|
2017-12-02 09:36:50 +01:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-12-14 07:36:28 +01:00
|
|
|
Upgrade to *HTTP/2.0* schema described in
|
2017-12-02 09:36:50 +01:00
|
|
|
[rfc section 3.2](https://http2.github.io/http2-spec/#rfc.section.3.2) is not supported.
|
2017-12-05 01:26:40 +01:00
|
|
|
Starting *HTTP/2* with prior knowledge is supported for both clear text connection
|
2017-12-02 09:36:50 +01:00
|
|
|
and tls connection. [rfc section 3.4](https://http2.github.io/http2-spec/#rfc.section.3.4)
|
|
|
|
|
2018-03-28 22:16:01 +02:00
|
|
|
Please check [example](https://github.com/actix/actix-web/tree/master/examples/tls)
|
|
|
|
for a concrete example.
|