-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttps.rs
41 lines (36 loc) · 1.22 KB
/
https.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// This requires running with:
//
// ```bash
// cargo run --example https --features native-tls-example
// ```
//
// Generate an identity like so:
//
// ```bash
// openssl req -x509 -newkey rsa:4096 -nodes -keyout localhost.key -out localhost.crt -days 3650
// openssl pkcs12 -export -out identity.p12 -inkey localhost.key -in localhost.crt -password pass:mypass
//
// ```
extern crate iron;
#[cfg(feature = "native-tls-example")]
extern crate hyper_native_tls;
#[cfg(feature = "native-tls-example")]
fn main() {
// Avoid unused errors due to conditional compilation ('native-tls-example' feature is not default)
use hyper_native_tls::NativeTlsServer;
use iron::{Iron, Request, Response};
use iron::status;
use std::result::Result;
let ssl = NativeTlsServer::new("identity.p12", "mypass").unwrap();
match Iron::new(|_: &mut Request| {
Ok(Response::with((status::Ok, "Hello world!")))
}).https("127.0.0.1:3000", ssl) {
Result::Ok(listening) => println!("{:?}", listening),
Result::Err(err) => panic!("{:?}", err),
}
// curl -vvvv https://127.0.0.1:3000/ -k
}
#[cfg(not(feature = "native-tls-example"))]
fn main() {
// We need to do this to make sure `cargo test` passes.
}