diff --git a/axum/src/extract/connect_info.rs b/axum/src/extract/connect_info.rs index 3b64e5f6..d3f735a8 100644 --- a/axum/src/extract/connect_info.rs +++ b/axum/src/extract/connect_info.rs @@ -4,8 +4,9 @@ //! //! [`Router::into_make_service_with_connect_info`]: crate::routing::Router::into_make_service_with_connect_info +use crate::extension::AddExtension; + use super::{Extension, FromRequestParts}; -use crate::{middleware::AddExtension, serve::IncomingStream}; use async_trait::async_trait; use http::request::Parts; use std::{ @@ -82,11 +83,16 @@ pub trait Connected: Clone + Send + Sync + 'static { fn connect_info(target: T) -> Self; } -impl Connected> for SocketAddr { - fn connect_info(target: IncomingStream<'_>) -> Self { - target.remote_addr() +#[cfg(all(feature = "tokio", feature = "http1"))] +const _: () = { + use crate::serve::IncomingStream; + + impl Connected> for SocketAddr { + fn connect_info(target: IncomingStream<'_>) -> Self { + target.remote_addr() + } } -} +}; impl Service for IntoMakeServiceWithConnectInfo where @@ -210,7 +216,7 @@ where #[cfg(test)] mod tests { use super::*; - use crate::{routing::get, test_helpers::TestClient, Router}; + use crate::{routing::get, test_helpers::TestClient, Router, serve::IncomingStream}; use std::net::SocketAddr; use tokio::net::TcpListener; diff --git a/axum/src/handler/service.rs b/axum/src/handler/service.rs index 35974a4c..fd8b8e68 100644 --- a/axum/src/handler/service.rs +++ b/axum/src/handler/service.rs @@ -178,7 +178,7 @@ where } // for `axum::serve(listener, handler)` -#[cfg(feature = "tokio")] +#[cfg(all(feature = "tokio", feature = "http1"))] const _: () = { use crate::serve::IncomingStream; diff --git a/axum/src/routing/method_routing.rs b/axum/src/routing/method_routing.rs index 8a83d8aa..c73fd496 100644 --- a/axum/src/routing/method_routing.rs +++ b/axum/src/routing/method_routing.rs @@ -1232,7 +1232,7 @@ where } // for `axum::serve(listener, router)` -#[cfg(feature = "tokio")] +#[cfg(all(feature = "tokio", feature = "http1"))] const _: () = { use crate::serve::IncomingStream; diff --git a/axum/src/routing/mod.rs b/axum/src/routing/mod.rs index f3d92c1c..75d1cefc 100644 --- a/axum/src/routing/mod.rs +++ b/axum/src/routing/mod.rs @@ -604,7 +604,7 @@ impl Router { } // for `axum::serve(listener, router)` -#[cfg(feature = "tokio")] +#[cfg(all(feature = "tokio", feature = "http1"))] const _: () = { use crate::serve::IncomingStream;