diff --git a/foundations/src/http/server/stream/quic.rs b/foundations/src/http/server/stream/quic.rs index cf8b72d0..2a4f77e7 100644 --- a/foundations/src/http/server/stream/quic.rs +++ b/foundations/src/http/server/stream/quic.rs @@ -169,6 +169,8 @@ impl Connection { } }; + let ip_addr = connection.remote_address().ip(); + let mut connection = match self .builder .build(h3_quinn::Connection::new(connection)) @@ -277,10 +279,9 @@ impl Connection { hijack_conn_tx: hijack_conn_tx.clone(), stream: stream.clone(), }); - request.extensions_mut().insert(SocketKind::Quic); - request.extensions_mut().insert(ctx.clone()); + request.extensions_mut().insert(ip_addr); let connection_context = connection_handle.context(); diff --git a/foundations/src/http/server/stream/tcp.rs b/foundations/src/http/server/stream/tcp.rs index 005e07fb..004948a8 100644 --- a/foundations/src/http/server/stream/tcp.rs +++ b/foundations/src/http/server/stream/tcp.rs @@ -111,6 +111,7 @@ impl Backend for TcpBackend { builder: self.builder.clone(), service, parent_ctx: ctx, + peer_addr: addr, keep_alive_timeout: self.keep_alive_timeout, } .serve() @@ -130,6 +131,7 @@ struct Connection { connection: TcpStream, builder: Arc>, service: S, + peer_addr: std::net::SocketAddr, parent_ctx: crate::context::Context, keep_alive_timeout: Option, } @@ -150,6 +152,8 @@ impl Connection { let active_requests = Arc::new(std::sync::atomic::AtomicUsize::new(0)); + let ip_addr = self.peer_addr.ip(); + let service_fn = { let service = self.service.clone(); let span = tracing::Span::current(); @@ -163,6 +167,7 @@ impl Connection { let ctx = make_ctx(); req.extensions_mut().insert(ctx.clone()); req.extensions_mut().insert(SocketKind::Tcp); + req.extensions_mut().insert(ip_addr); let resp = service.on_request(req.map(Body::new)).await.into_response(); drop(ctx); drop(guard); diff --git a/foundations/src/http/server/stream/tls.rs b/foundations/src/http/server/stream/tls.rs index 75cf19ce..365121e6 100644 --- a/foundations/src/http/server/stream/tls.rs +++ b/foundations/src/http/server/stream/tls.rs @@ -121,6 +121,7 @@ impl Backend for TlsBackend { acceptor: self.acceptor.clone(), service, parent_ctx: ctx, + peer_addr: addr, keep_alive_timeout: self.keep_alive_timeout, } .serve() @@ -141,6 +142,7 @@ struct Connection { builder: Arc>, acceptor: Arc, service: S, + peer_addr: std::net::SocketAddr, keep_alive_timeout: Option, parent_ctx: crate::context::Context, } @@ -174,6 +176,8 @@ impl Connection { Arc::new(move || handle.context()) }; + let ip_addr = self.peer_addr.ip(); + let active_requests = Arc::new(std::sync::atomic::AtomicUsize::new(0)); let service_fn = { @@ -190,6 +194,7 @@ impl Connection { let ctx = make_ctx(); req.extensions_mut().insert(ctx.clone()); req.extensions_mut().insert(SocketKind::TlsTcp); + req.extensions_mut().insert(ip_addr); let resp = service.on_request(req.map(Body::new)).await.into_response(); drop(ctx); drop(guard);