1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-25 09:59:21 +02:00

add ssl guide ref

This commit is contained in:
Nikolay Kim
2017-12-13 21:56:30 -08:00
parent 406ef20262
commit 408ddf0be1
4 changed files with 39 additions and 5 deletions

View File

@ -26,9 +26,9 @@ fn main() {
let pkcs12 = Pkcs12::from_der(&pkcs12).unwrap().parse("12345").unwrap();
HttpServer::new(
Application::new("/")
.resource("/index.html", |r| r.f(index))
.serve_tls::<_, ()>("127.0.0.1:8080", pkcs12).unwrap();
|| Application::new()
.resource("/index.html", |r| r.f(index)))
.serve_ssl::<_, ()>("127.0.0.1:8080", pkcs12).unwrap();
}
```

View File

@ -25,6 +25,40 @@ Server create separate application instance for each created worker. Application
is not shared between threads, to share state `Arc` could be used. Application state
does not need to be `Send` and `Sync` but application factory must be `Send` + `Sync`.
## SSL
There are two `tls` and `alpn` features for ssl server. `tls` feature is for `native-tls`
integration and `alpn` is for `openssl`.
```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::new()
.resource("/index.html", |r| r.f(index)))
.serve_ssl::<_, ()>("127.0.0.1:8080", pkcs12).unwrap();
}
```
Note on *HTTP/2* protocol over tls without prior knowlage, it requires
[tls alpn](https://tools.ietf.org/html/rfc7301). At the moment only
`openssl` has `alpn ` support.
Please check [example](https://github.com/actix/actix-web/tree/master/examples/tls)
for concrete example.
## Keep-Alive
Actix can wait for requesta on a keep-alive connection. *Keep alive*