feat: add actix with rustls
This commit is contained in:
36
actix_rustls/src/main.rs
Normal file
36
actix_rustls/src/main.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use std::sync::Arc;
|
||||
use rustls::ClientHello;
|
||||
use rustls::NoClientAuth;
|
||||
use rustls::ServerConfig;
|
||||
use rustls::ResolvesServerCert;
|
||||
use rustls::sign::CertifiedKey;
|
||||
use actix_web::App;
|
||||
use actix_web::HttpServer;
|
||||
use actix_web::get;
|
||||
use actix_web::Responder;
|
||||
|
||||
struct CustomResolvesServerCert;
|
||||
impl ResolvesServerCert for CustomResolvesServerCert {
|
||||
fn resolve(&self, client_hello: ClientHello) -> Option<CertifiedKey> {
|
||||
println!("Request server name: {:?}", client_hello.server_name());
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
async fn index() -> impl Responder {
|
||||
format!("Hello world!")
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
let mut config = ServerConfig::new(NoClientAuth::new());
|
||||
config.cert_resolver = Arc::new(CustomResolvesServerCert);
|
||||
|
||||
let listen = "127.0.0.1:8443";
|
||||
println!("Listen at: {}", listen);
|
||||
HttpServer::new(|| App::new().service(index))
|
||||
.bind_rustls(listen, config)?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
Reference in New Issue
Block a user