-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from tomaka/ssl
Implement HTTPS
- Loading branch information
Showing
11 changed files
with
338 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICUzCCAbwCCQCBrI63G7tNbzANBgkqhkiG9w0BAQsFADBtMQswCQYDVQQGEwJO | ||
TzENMAsGA1UECAwETm9uZTENMAsGA1UEBwwETm9uZTENMAsGA1UECgwETm9uZTEN | ||
MAsGA1UECwwETm9uZTENMAsGA1UEAwwETm9uZTETMBEGCSqGSIb3DQEJARYETm9u | ||
ZTAgFw0xNTExMjQxNDIwNDVaGA8yMDcwMDgyNzE0MjA0NVowbTELMAkGA1UEBhMC | ||
Tk8xDTALBgNVBAgMBE5vbmUxDTALBgNVBAcMBE5vbmUxDTALBgNVBAoMBE5vbmUx | ||
DTALBgNVBAsMBE5vbmUxDTALBgNVBAMMBE5vbmUxEzARBgkqhkiG9w0BCQEWBE5v | ||
bmUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMKwa7v9rjWAcGNieV33ePxA | ||
b+JtvyY12CuX2nR4jVllGubJhyaqKOpM1TryWo6B9nc7bSe4wO23VBqd4e8WwBW3 | ||
GD0qEuf0qFF/VyUZAZ3qJRqs1HUnBNMTC+BWdFNMzi8NTvnbHXZad5ECuFcQoiCk | ||
qFPa2ixopNejZTNwNA2tAgMBAAEwDQYJKoZIhvcNAQELBQADgYEAC9rxM6bMSsJH | ||
b2SSzKh5m/cVJFC9yNWl2w2ge3Hm1TSJv80X3jUUQ2DLnPM3sE6yd1rLfq10qiVc | ||
SbbWihmmBzx0OJMlo6Eg29m2Q5chV6mzBbfYZcbAE3iceDj6JXJLjJoqHs+39X/R | ||
IP/a+TP8gZZ8VfvV3Z0tfqT5e8AkvPM= | ||
-----END CERTIFICATE----- |
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,15 @@ | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIICXQIBAAKBgQDCsGu7/a41gHBjYnld93j8QG/ibb8mNdgrl9p0eI1ZZRrmyYcm | ||
qijqTNU68lqOgfZ3O20nuMDtt1QaneHvFsAVtxg9KhLn9KhRf1clGQGd6iUarNR1 | ||
JwTTEwvgVnRTTM4vDU752x12WneRArhXEKIgpKhT2tosaKTXo2UzcDQNrQIDAQAB | ||
AoGABDx2e6avbbaXu3HfFi5WUZbNWG3u5NPzGi+5ryMYYEOU7ESiTjMRpNd7JEc1 | ||
tTgatslyPJUGjaWZjOK2kc866rRSw38y3bH8AhMdcvpBn27BOoi5RgFrtpwe8CAQ | ||
rZ7PcXusKDNzhFyaue4a2qUqszcv8nMhOtVE0ZmIrmOUOQECQQDmi0HfzJvE01pk | ||
bRez6vZHnmsfb8jzR1+yUMPeiIqelESdlApnaT7PIo1JapAfQHOznB6ZPbdnXdyj | ||
3rkv2zFhAkEA2C+pbzD0EV3AVBaOtFR3dHMQ3MbroPDJ8BJQtYhicbcrlSK48n94 | ||
goUH4hglAl/Pyg/dGLzHIxcSRdkScLVjzQJBANy503YMFc8ac97Wu+zcNrNXL0TH | ||
5+NUIIE+5mj23ZD6b79W76cWkrYKZK83wYjKUnxSKtGYzzG+IfMa2L7C48ECQQCK | ||
kxqfrJh2XUsAW6lDzHT5zxw6+MNnWZGH8qWLh43a6JfmM+irgKwltdJUyjdG61WN | ||
Z1fJGJDpXEuZPEjGuG7tAkAMsCe/44GCLSzSiORACdtyO63Cu6JCz2dqdYtTgJdw | ||
l+bnX9B8o4lTgltdJWQ/5DAoscNJTtnNBfj4xgxKIkfW | ||
-----END RSA PRIVATE KEY----- |
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,31 @@ | ||
extern crate tiny_http; | ||
|
||
#[cfg(not(feature = "ssl"))] | ||
fn main() { println!("This example requires the `ssl` feature to be enabled"); } | ||
|
||
#[cfg(feature = "ssl")] | ||
fn main() { | ||
use tiny_http::{Server, Response}; | ||
|
||
let server = Server::https("0.0.0.0:8000", tiny_http::SslConfig { | ||
certificate: include_bytes!("ssl-cert.pem").to_vec(), | ||
private_key: include_bytes!("ssl-key.pem").to_vec(), | ||
}).unwrap(); | ||
|
||
println!("Note: connecting to this server will likely give you a warning from your browser \ | ||
because the connection is unsecure. This is because the certificate used by this \ | ||
example is self-signed. With a real certificate, you wouldn't get this warning."); | ||
|
||
for request in server.incoming_requests() { | ||
assert!(request.secure()); | ||
|
||
println!("received request! method: {:?}, url: {:?}, headers: {:?}", | ||
request.method(), | ||
request.url(), | ||
request.headers() | ||
); | ||
|
||
let response = Response::from_string("hello world"); | ||
request.respond(response); | ||
} | ||
} |
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
Oops, something went wrong.