mirror of
https://github.com/actix/examples
synced 2025-04-06 18:18:50 +02:00
Simplify http-to-https example
This commit is contained in:
parent
a554e6467e
commit
54ed931e80
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2047,7 +2047,6 @@ dependencies = [
|
||||
"log",
|
||||
"notify 6.1.1",
|
||||
"rustls 0.23.25",
|
||||
"rustls-pemfile 2.2.0",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
@ -5094,7 +5093,6 @@ dependencies = [
|
||||
"futures-util",
|
||||
"log",
|
||||
"rustls 0.23.25",
|
||||
"rustls-pemfile 2.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -112,7 +112,6 @@ rand = "0.9"
|
||||
redis = { version = "0.27" }
|
||||
reqwest = { version = "0.12", features = ["json", "stream"] }
|
||||
rustls = "0.23"
|
||||
rustls-pemfile = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
time = "0.3"
|
||||
|
@ -9,4 +9,3 @@ env_logger.workspace = true
|
||||
futures-util.workspace = true
|
||||
log.workspace = true
|
||||
rustls.workspace = true
|
||||
rustls-pemfile.workspace = true
|
||||
|
@ -1,9 +1,9 @@
|
||||
use std::{fs::File, io::BufReader};
|
||||
|
||||
use actix_web::{App, HttpResponse, HttpServer, dev::Service, get, http};
|
||||
use futures_util::future::{self, Either, FutureExt};
|
||||
use rustls::{ServerConfig, pki_types::PrivateKeyDer};
|
||||
use rustls_pemfile::{certs, pkcs8_private_keys};
|
||||
use rustls::{
|
||||
ServerConfig,
|
||||
pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject},
|
||||
};
|
||||
|
||||
#[get("/")]
|
||||
async fn index() -> String {
|
||||
@ -18,18 +18,17 @@ async fn main() -> std::io::Result<()> {
|
||||
.install_default()
|
||||
.unwrap();
|
||||
|
||||
let cert_file = &mut BufReader::new(File::open("cert.pem").unwrap());
|
||||
let key_file = &mut BufReader::new(File::open("key.pem").unwrap());
|
||||
let cert_chain = CertificateDer::pem_file_iter("cert.pem")
|
||||
.unwrap()
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
let cert_chain = certs(cert_file).collect::<Result<Vec<_>, _>>().unwrap();
|
||||
let mut keys = pkcs8_private_keys(key_file)
|
||||
.map(|key| key.map(PrivateKeyDer::Pkcs8))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
let key_der =
|
||||
PrivateKeyDer::from_pem_file("key.pem").expect("Could not locate PKCS 8 private keys.");
|
||||
|
||||
let config = ServerConfig::builder()
|
||||
.with_no_client_auth()
|
||||
.with_single_cert(cert_chain, keys.remove(0))
|
||||
.with_single_cert(cert_chain, key_der)
|
||||
.unwrap();
|
||||
|
||||
log::info!(
|
||||
|
Loading…
x
Reference in New Issue
Block a user