use std::net::SocketAddr;
use hyper::server::conn::AddrStream;
use axum::extract::connect_info::Connected;
use axum::serve::IncomingStream;

#[derive(Clone, Debug)]
pub struct AppConnectInfo {
   pub remote_addr: SocketAddr, 
   pub local_addr: SocketAddr, 
}
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()),
        }
    }
}
impl Connected<&AddrStream> for AppConnectInfo {
    fn connect_info(target: &AddrStream) -> Self {
        AppConnectInfo {
            remote_addr: target.remote_addr(),
            local_addr: target.local_addr(),
        }
    }
}
