-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to start tls server with HttpServer::serve_tls
- Loading branch information
Showing
8 changed files
with
152 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "ssl-example" | ||
version = "0.1.0" | ||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"] | ||
|
||
[[bin]] | ||
name = "server" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
env_logger = "0.4" | ||
|
||
actix = "0.3.1" | ||
actix-web = { path = "../../", features=["tls"] } |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#![allow(unused_variables)] | ||
extern crate actix; | ||
extern crate actix_web; | ||
extern crate env_logger; | ||
|
||
//use tokio_tls; | ||
use std::fs::File; | ||
use std::io::Read; | ||
// use native_tls::{TlsAcceptor, TlsStream}; | ||
|
||
use actix_web::*; | ||
|
||
/// somple handle | ||
fn index(req: &mut HttpRequest, _payload: Payload, state: &()) -> HttpResponse { | ||
println!("{:?}", req); | ||
httpcodes::HTTPOk.with_body("Welcome!") | ||
} | ||
|
||
fn main() { | ||
::std::env::set_var("RUST_LOG", "actix_web=info"); | ||
let _ = env_logger::init(); | ||
let sys = actix::System::new("ws-example"); | ||
|
||
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, "12345").unwrap(); | ||
|
||
HttpServer::new( | ||
Application::default("/") | ||
// enable logger | ||
.middleware(Logger::new(None)) | ||
// register simple handler, handle all methods | ||
.handler("/index.html", index) | ||
// with path parameters | ||
.resource("/", |r| r.handler(Method::GET, |req, _, _| { | ||
Ok(httpcodes::HTTPFound | ||
.builder() | ||
.header("LOCATION", "/index.html") | ||
.body(Body::Empty)?) | ||
}))) | ||
.serve_tls::<_, ()>("127.0.0.1:8080", pkcs12).unwrap(); | ||
|
||
println!("Started http server: 127.0.0.1:8080"); | ||
let _ = sys.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters