docserver/src/defs/app_connect_info.rs

29 lines
885 B
Rust
Raw Normal View History

2023-07-19 03:00:41 +00:00
use std::net::SocketAddr;
//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 {
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(),
// local_addr: target.local_addr().unwrap_or(target.remote_addr()),
2023-08-14 20:37:38 +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 {
remote_addr: target.to_owned(),
// local_addr: target.to_owned(),
2023-07-19 03:00:41 +00:00
}
}
}