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