From 568a8e9dfaefc8e60e23542eaca1a33eaf8976dd Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 14 Feb 2022 01:05:44 +0000 Subject: [PATCH] fix client cert example fixes rustls-client-cert example not working #526 --- security/rustls-client-cert/src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/security/rustls-client-cert/src/main.rs b/security/rustls-client-cert/src/main.rs index 19b7f48b..778814d6 100644 --- a/security/rustls-client-cert/src/main.rs +++ b/security/rustls-client-cert/src/main.rs @@ -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, } -async fn route_whoami( - conn_info: web::ReqData, - client_cert: Option>, -) -> impl Responder { +async fn route_whoami(req: HttpRequest) -> impl Responder { + let conn_info = req.conn_data::().unwrap(); + let client_cert = req.conn_data::(); + if let Some(cert) = client_cert { HttpResponse::Ok().body(format!("{:?}\n\n{:?}", &conn_info, &cert)) } else {