1
0
mirror of https://github.com/actix/examples synced 2025-01-22 22:05:57 +01:00

fix client cert example

fixes rustls-client-cert example not working #526
This commit is contained in:
Rob Ede 2022-02-14 01:05:44 +00:00
parent 0b74135fb0
commit 568a8e9dfa
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933

View File

@ -1,12 +1,12 @@
//! This example shows how to use `actix_web::HttpServer::on_connect` to access client certificates
//! pass them to a handler through request-local data.
//! pass them to a handler through connection-local data.
use std::{any::Any, env, fs::File, io::BufReader, net::SocketAddr};
use actix_tls::accept::rustls::reexports::ServerConfig;
use actix_tls::accept::rustls::TlsStream;
use actix_tls::accept::rustls::{reexports::ServerConfig, TlsStream};
use actix_web::{
dev::Extensions, rt::net::TcpStream, web, App, HttpResponse, HttpServer, Responder,
dev::Extensions, rt::net::TcpStream, web, App, HttpRequest, HttpResponse,
HttpServer, Responder,
};
use log::info;
use rustls::{
@ -27,10 +27,10 @@ struct ConnectionInfo {
ttl: Option<u32>,
}
async fn route_whoami(
conn_info: web::ReqData<ConnectionInfo>,
client_cert: Option<web::ReqData<Certificate>>,
) -> impl Responder {
async fn route_whoami(req: HttpRequest) -> impl Responder {
let conn_info = req.conn_data::<ConnectionInfo>().unwrap();
let client_cert = req.conn_data::<Certificate>();
if let Some(cert) = client_cert {
HttpResponse::Ok().body(format!("{:?}\n\n{:?}", &conn_info, &cert))
} else {