mirror of
https://github.com/fafhrd91/actix-web
synced 2024-12-01 02:54:36 +01:00
45 lines
1.5 KiB
Markdown
45 lines
1.5 KiB
Markdown
# HTTP/2.0
|
|
|
|
Actix web automatically upgrades connection to *HTTP/2.0* if possible.
|
|
|
|
## Negotiation
|
|
|
|
*HTTP/2.0* protocol over tls without prior knowledge requires
|
|
[tls alpn](https://tools.ietf.org/html/rfc7301). At the moment only
|
|
`rust-openssl` has support. Turn on the `alpn` feature to enable `alpn` negotiation.
|
|
With enabled `alpn` feature `HttpServer` provides the
|
|
[serve_tls](../actix_web/struct.HttpServer.html#method.serve_tls) method.
|
|
|
|
```toml
|
|
[dependencies]
|
|
actix-web = { version = "0.3.3", features=["alpn"] }
|
|
openssl = { version="0.10", features = ["v110"] }
|
|
```
|
|
|
|
```rust,ignore
|
|
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();
|
|
}
|
|
```
|
|
|
|
Upgrade to *HTTP/2.0* 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 a concrete example.
|