feat: add actix with rustls

This commit is contained in:
2020-10-10 22:13:01 +08:00
parent b685938431
commit 6d3713f35e
4 changed files with 1916 additions and 0 deletions

36
actix_rustls/src/main.rs Normal file
View 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
}