mirror of
https://github.com/actix/examples
synced 2025-02-02 09:39:03 +01:00
fix client cert example
fixes rustls-client-cert example not working #526
This commit is contained in:
parent
0b74135fb0
commit
568a8e9dfa
@ -1,12 +1,12 @@
|
|||||||
//! This example shows how to use `actix_web::HttpServer::on_connect` to access client certificates
|
//! 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 std::{any::Any, env, fs::File, io::BufReader, net::SocketAddr};
|
||||||
|
|
||||||
use actix_tls::accept::rustls::reexports::ServerConfig;
|
use actix_tls::accept::rustls::{reexports::ServerConfig, TlsStream};
|
||||||
use actix_tls::accept::rustls::TlsStream;
|
|
||||||
use actix_web::{
|
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 log::info;
|
||||||
use rustls::{
|
use rustls::{
|
||||||
@ -27,10 +27,10 @@ struct ConnectionInfo {
|
|||||||
ttl: Option<u32>,
|
ttl: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn route_whoami(
|
async fn route_whoami(req: HttpRequest) -> impl Responder {
|
||||||
conn_info: web::ReqData<ConnectionInfo>,
|
let conn_info = req.conn_data::<ConnectionInfo>().unwrap();
|
||||||
client_cert: Option<web::ReqData<Certificate>>,
|
let client_cert = req.conn_data::<Certificate>();
|
||||||
) -> impl Responder {
|
|
||||||
if let Some(cert) = client_cert {
|
if let Some(cert) = client_cert {
|
||||||
HttpResponse::Ok().body(format!("{:?}\n\n{:?}", &conn_info, &cert))
|
HttpResponse::Ok().body(format!("{:?}\n\n{:?}", &conn_info, &cert))
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user