1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-16 13:16:34 +00:00

update examples/tls/README

This commit is contained in:
ami44 2017-12-30 16:24:50 +01:00
parent 8e580ef7b9
commit a1dc5a6bd1
3 changed files with 22 additions and 5 deletions

View file

@ -9,5 +9,5 @@ path = "src/main.rs"
[dependencies] [dependencies]
env_logger = "0.4" env_logger = "0.4"
actix = "^0.3.1" actix = { version = "^0.3.5" }
actix-web = { git = "https://github.com/actix/actix-web.git", features=["alpn"] } actix-web = { git = "https://github.com/actix/actix-web", features=["signal", "alpn"] }

View file

@ -1,5 +1,16 @@
# tls example # tls example
To start server use command: `cargo run` ## Usage
Test command: `curl -v https://127.0.0.1:8080/index.html --compress -k` ### server
```bash
cd actix-web/examples/tls
cargo run (or ``cargo watch -x run``)
# Started http server: 127.0.0.1:8443
```
### web client
- curl: ``curl -v https://127.0.0.1:8443/index.html --compress -k``
- browser: [https://127.0.0.1:8443/index.html](https://127.0.0.1:8080/index.html)

View file

@ -7,6 +7,8 @@ use std::fs::File;
use std::io::Read; use std::io::Read;
use actix_web::*; use actix_web::*;
use actix::Arbiter;
use actix::actors::signal::{ProcessSignals, Subscribe};
/// somple handle /// somple handle
fn index(req: HttpRequest) -> Result<HttpResponse> { fn index(req: HttpRequest) -> Result<HttpResponse> {
@ -29,7 +31,7 @@ fn main() {
file.read_to_end(&mut pkcs12).unwrap(); file.read_to_end(&mut pkcs12).unwrap();
let pkcs12 = Pkcs12::from_der(&pkcs12).unwrap().parse("12345").unwrap(); let pkcs12 = Pkcs12::from_der(&pkcs12).unwrap().parse("12345").unwrap();
HttpServer::new( let addr = HttpServer::new(
|| Application::new() || Application::new()
// enable logger // enable logger
.middleware(middleware::Logger::default()) .middleware(middleware::Logger::default())
@ -45,6 +47,10 @@ fn main() {
.bind("127.0.0.1:8443").unwrap() .bind("127.0.0.1:8443").unwrap()
.start_ssl(&pkcs12).unwrap(); .start_ssl(&pkcs12).unwrap();
// Subscribe to unix signals
let signals = Arbiter::system_registry().get::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber()));
println!("Started http server: 127.0.0.1:8443"); println!("Started http server: 127.0.0.1:8443");
let _ = sys.run(); let _ = sys.run();
} }