2023-07-19 03:00:41 +00:00
|
|
|
use std::net::SocketAddr;
|
2024-08-14 16:34:50 +00:00
|
|
|
//use hyper::server::conn::AddrStream;
|
2023-07-19 03:00:41 +00:00
|
|
|
use axum::extract::connect_info::Connected;
|
2023-08-14 20:37:38 +00:00
|
|
|
use axum::serve::IncomingStream;
|
2023-07-19 03:00:41 +00:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct AppConnectInfo {
|
2024-08-14 16:34:50 +00:00
|
|
|
pub remote_addr: SocketAddr,
|
|
|
|
// pub local_addr: SocketAddr,
|
2023-07-19 03:00:41 +00:00
|
|
|
}
|
2023-08-14 20:37:38 +00:00
|
|
|
impl Connected<IncomingStream<'_>> for AppConnectInfo {
|
|
|
|
fn connect_info(target: IncomingStream<'_>) -> Self {
|
|
|
|
AppConnectInfo {
|
|
|
|
remote_addr: target.remote_addr(),
|
2024-08-14 16:34:50 +00:00
|
|
|
// local_addr: target.local_addr().unwrap_or(target.remote_addr()),
|
2023-08-14 20:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-14 16:34:50 +00:00
|
|
|
// impl Connected<&AddrStream> for AppConnectInfo {
|
|
|
|
// fn connect_info(target: &AddrStream) -> Self {
|
|
|
|
impl Connected<SocketAddr> for AppConnectInfo {
|
|
|
|
fn connect_info(target: SocketAddr) -> Self {
|
2023-07-19 03:00:41 +00:00
|
|
|
AppConnectInfo {
|
2024-08-14 16:34:50 +00:00
|
|
|
remote_addr: target.to_owned(),
|
|
|
|
// local_addr: target.to_owned(),
|
2023-07-19 03:00:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|