1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01: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

@ -42,7 +42,7 @@ fn main() {
.header("LOCATION", "/index.html") .header("LOCATION", "/index.html")
.body(Body::Empty) .body(Body::Empty)
}))) })))
.serve_tls::<_, ()>("127.0.0.1:8443", &pkcs12).unwrap(); .serve_ssl::<_, ()>("127.0.0.1:8443", &pkcs12).unwrap();
println!("Started http server: 127.0.0.1:8443"); println!("Started http server: 127.0.0.1:8443");
let _ = sys.run(); let _ = sys.run();

View File

@ -26,9 +26,9 @@ fn main() {
let pkcs12 = Pkcs12::from_der(&pkcs12).unwrap().parse("12345").unwrap(); let pkcs12 = Pkcs12::from_der(&pkcs12).unwrap().parse("12345").unwrap();
HttpServer::new( HttpServer::new(
Application::new("/") || Application::new()
.resource("/index.html", |r| r.f(index)) .resource("/index.html", |r| r.f(index)))
.serve_tls::<_, ()>("127.0.0.1:8080", pkcs12).unwrap(); .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 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`. 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 ## Keep-Alive
Actix can wait for requesta on a keep-alive connection. *Keep alive* Actix can wait for requesta on a keep-alive connection. *Keep alive*

View File

@ -334,7 +334,7 @@ impl<H: HttpHandler, U, V> HttpServer<SslStream<TcpStream>, net::SocketAddr, H,
/// ///
/// This methods converts address to list of `SocketAddr` /// This methods converts address to list of `SocketAddr`
/// then binds to all available addresses. /// then binds to all available addresses.
pub fn serve_tls<S, Addr>(mut self, addr: S, identity: &ParsedPkcs12) -> io::Result<Addr> pub fn serve_ssl<S, Addr>(mut self, addr: S, identity: &ParsedPkcs12) -> io::Result<Addr>
where Self: ActorAddress<Self, Addr>, where Self: ActorAddress<Self, Addr>,
S: net::ToSocketAddrs, S: net::ToSocketAddrs,
{ {