diff --git a/build.rs b/build.rs new file mode 100644 index 0000000000..bfde27e3f4 --- /dev/null +++ b/build.rs @@ -0,0 +1,77 @@ +fn main() { + // Add to the list of expected config names and values that is used when checking the reachable + // cfg expressions with the unexpected_cfgs lint. + // + // See https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-check-cfg + println!("cargo:rustc-check-cfg=cfg(http1)"); + println!("cargo:rustc-check-cfg=cfg(http2)"); + println!("cargo:rustc-check-cfg=cfg(client)"); + println!("cargo:rustc-check-cfg=cfg(server)"); + println!("cargo:rustc-check-cfg=cfg(ffi)"); + println!("cargo:rustc-check-cfg=cfg(full)"); + println!("cargo:rustc-check-cfg=cfg(nightly)"); + println!("cargo:rustc-check-cfg=cfg(runtime)"); // TODO evaluate if this is needed (see below) + println!("cargo:rustc-check-cfg=cfg(tracing)"); + println!("cargo:rustc-check-cfg=cfg(http_client)"); + println!("cargo:rustc-check-cfg=cfg(http1_client)"); + println!("cargo:rustc-check-cfg=cfg(http2_client)"); + println!("cargo:rustc-check-cfg=cfg(http_server)"); + println!("cargo:rustc-check-cfg=cfg(http1_server)"); + println!("cargo:rustc-check-cfg=cfg(http2_server)"); + + // Add cfg flags that simplify using cfg expressions in the code. e.g. instead of + // `#[cfg(all(any(feature = "http1", feature = "http2"), feature = "server")]` you can use + // `#[cfg(http_server)]` + // + // See https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-cfg + #[cfg(feature = "http1")] + println!("cargo:rustc-cfg=http1"); + + #[cfg(feature = "http2")] + println!("cargo:rustc-cfg=http2"); + + #[cfg(any(feature = "http1", feature = "http2"))] + println!("cargo:rustc-cfg=http"); + + #[cfg(feature = "client")] + println!("cargo:rustc-cfg=client"); + + #[cfg(feature = "server")] + println!("cargo:rustc-cfg=server"); + + #[cfg(feature = "ffi")] + println!("cargo:rustc-cfg=ffi"); + + #[cfg(feature = "full")] + println!("cargo:rustc-cfg=full"); + + #[cfg(feature = "nightly")] + println!("cargo:rustc-cfg=nightly"); + + // TODO: this feature doesn't actually exist in the cargo.toml + // this condition was added to simplify the conditions in src/mock.rs, but I'm not sure if those + // conditions were actually working as intended + // #[cfg(feature = "runtime")] + // println!("cargo:rustc-cfg=runtime"); + + #[cfg(feature = "tracing")] + println!("cargo:rustc-cfg=tracing"); + + #[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))] + println!("cargo:rustc-cfg=http_client"); + + #[cfg(all(feature = "http1", feature = "client"))] + println!("cargo:rustc-cfg=http1_client"); + + #[cfg(all(feature = "http2", feature = "client"))] + println!("cargo:rustc-cfg=http2_client"); + + #[cfg(all(any(feature = "http1", feature = "http2"), feature = "server"))] + println!("cargo:rustc-cfg=http_server"); + + #[cfg(all(feature = "http1", feature = "server"))] + println!("cargo:rustc-cfg=http1_server"); + + #[cfg(all(feature = "http2", feature = "server"))] + println!("cargo:rustc-cfg=http2_server"); +} diff --git a/examples/hello-http2.rs b/examples/hello-http2.rs index 810ca7e64b..0f4c8dd3b9 100644 --- a/examples/hello-http2.rs +++ b/examples/hello-http2.rs @@ -3,7 +3,7 @@ use http_body_util::Full; use hyper::body::Bytes; -#[cfg(feature = "server")] +#[cfg(server)] use hyper::server::conn::http2; use hyper::service::service_fn; use hyper::{Request, Response}; @@ -19,7 +19,7 @@ use support::TokioIo; // An async function that consumes a request, does nothing with it and returns a // response. -#[cfg(feature = "server")] +#[cfg(server)] async fn hello(_: Request) -> Result>, Infallible> { Ok(Response::new(Full::new(Bytes::from("Hello, World!")))) } @@ -42,7 +42,7 @@ where } } -#[cfg(feature = "server")] +#[cfg(server)] #[tokio::main] async fn main() -> Result<(), Box> { pretty_env_logger::init(); @@ -83,7 +83,7 @@ async fn main() -> Result<(), Box> { } } -#[cfg(not(feature = "server"))] +#[cfg(not(server))] fn main() { panic!("This example requires the 'server' feature to be enabled"); } diff --git a/src/body/incoming.rs b/src/body/incoming.rs index dcdc440524..1d370031e9 100644 --- a/src/body/incoming.rs +++ b/src/body/incoming.rs @@ -1,36 +1,30 @@ use std::fmt; -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; use bytes::Bytes; -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] use futures_channel::{mpsc, oneshot}; -#[cfg(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") -))] +#[cfg(any(http_client, http_server))] use futures_util::ready; -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] use futures_util::{stream::FusedStream, Stream}; // for mpsc::Receiver -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] use http::HeaderMap; use http_body::{Body, Frame, SizeHint}; -#[cfg(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") -))] +#[cfg(any(http_client, http_server))] use super::DecodedLength; -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] use crate::common::watch; -#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))] +#[cfg(any(http2_client, http2_server))] use crate::proto::h2::ping; -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] type BodySender = mpsc::Sender>; -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] type TrailersSender = oneshot::Sender; /// A stream of `Bytes`, used when receiving bodies from the network. @@ -55,21 +49,21 @@ pub struct Incoming { enum Kind { Empty, - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] Chan { content_length: DecodedLength, want_tx: watch::Sender, data_rx: mpsc::Receiver>, trailers_rx: oneshot::Receiver, }, - #[cfg(all(feature = "http2", any(feature = "client", feature = "server")))] + #[cfg(any(http2_client, http2_server))] H2 { content_length: DecodedLength, data_done: bool, ping: ping::Recorder, recv: h2::RecvStream, }, - #[cfg(feature = "ffi")] + #[cfg(ffi)] Ffi(crate::ffi::UserBody), } @@ -87,30 +81,30 @@ enum Kind { /// [`Body::channel()`]: struct.Body.html#method.channel /// [`Sender::abort()`]: struct.Sender.html#method.abort #[must_use = "Sender does nothing unless sent on"] -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] pub(crate) struct Sender { want_rx: watch::Receiver, data_tx: BodySender, trailers_tx: Option, } -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] const WANT_PENDING: usize = 1; -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] const WANT_READY: usize = 2; impl Incoming { /// Create a `Body` stream with an associated sender half. /// /// Useful when wanting to stream chunks from another thread. - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] #[inline] #[cfg(test)] pub(crate) fn channel() -> (Sender, Incoming) { Self::new_channel(DecodedLength::CHUNKED, /*wanter =*/ false) } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] pub(crate) fn new_channel(content_length: DecodedLength, wanter: bool) -> (Sender, Incoming) { let (data_tx, data_rx) = mpsc::channel(0); let (trailers_tx, trailers_rx) = oneshot::channel(); @@ -145,12 +139,12 @@ impl Incoming { Incoming::new(Kind::Empty) } - #[cfg(feature = "ffi")] + #[cfg(ffi)] pub(crate) fn ffi() -> Incoming { Incoming::new(Kind::Ffi(crate::ffi::UserBody::new())) } - #[cfg(all(feature = "http2", any(feature = "client", feature = "server")))] + #[cfg(any(http2_client, http2_server))] pub(crate) fn h2( recv: h2::RecvStream, mut content_length: DecodedLength, @@ -170,7 +164,7 @@ impl Incoming { }) } - #[cfg(feature = "ffi")] + #[cfg(ffi)] pub(crate) fn as_ffi_mut(&mut self) -> &mut crate::ffi::UserBody { match self.kind { Kind::Ffi(ref mut body) => return body, @@ -191,26 +185,14 @@ impl Body for Incoming { type Error = crate::Error; fn poll_frame( - #[cfg_attr( - not(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") - )), - allow(unused_mut) - )] - mut self: Pin<&mut Self>, - #[cfg_attr( - not(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") - )), - allow(unused_variables) - )] - cx: &mut Context<'_>, + #[cfg_attr(not(any(http_client, http_server)), allow(unused_mut))] mut self: Pin<&mut Self>, + #[cfg_attr(not(any(http_client, http_server)), allow(unused_variables))] cx: &mut Context< + '_, + >, ) -> Poll, Self::Error>>> { match self.kind { Kind::Empty => Poll::Ready(None), - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] Kind::Chan { content_length: ref mut len, ref mut data_rx, @@ -232,7 +214,7 @@ impl Body for Incoming { Err(_) => Poll::Ready(None), } } - #[cfg(all(feature = "http2", any(feature = "client", feature = "server")))] + #[cfg(any(http2_client, http2_server))] Kind::H2 { ref mut data_done, ref ping, @@ -274,7 +256,7 @@ impl Body for Incoming { } } - #[cfg(feature = "ffi")] + #[cfg(ffi)] Kind::Ffi(ref mut body) => body.poll_data(cx), } } @@ -282,20 +264,17 @@ impl Body for Incoming { fn is_end_stream(&self) -> bool { match self.kind { Kind::Empty => true, - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] Kind::Chan { content_length, .. } => content_length == DecodedLength::ZERO, - #[cfg(all(feature = "http2", any(feature = "client", feature = "server")))] + #[cfg(any(http2_client, http2_server))] Kind::H2 { recv: ref h2, .. } => h2.is_end_stream(), - #[cfg(feature = "ffi")] + #[cfg(ffi)] Kind::Ffi(..) => false, } } fn size_hint(&self) -> SizeHint { - #[cfg(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") - ))] + #[cfg(any(http_client, http_server))] fn opt_len(decoded_length: DecodedLength) -> SizeHint { if let Some(content_length) = decoded_length.into_opt() { SizeHint::with_exact(content_length) @@ -306,11 +285,11 @@ impl Body for Incoming { match self.kind { Kind::Empty => SizeHint::with_exact(0), - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] Kind::Chan { content_length, .. } => opt_len(content_length), - #[cfg(all(feature = "http2", any(feature = "client", feature = "server")))] + #[cfg(any(http2_client, http2_server))] Kind::H2 { content_length, .. } => opt_len(content_length), - #[cfg(feature = "ffi")] + #[cfg(ffi)] Kind::Ffi(..) => SizeHint::default(), } } @@ -318,13 +297,7 @@ impl Body for Incoming { impl fmt::Debug for Incoming { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - #[cfg(any( - all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") - ), - feature = "ffi" - ))] + #[cfg(any(http_client, http_server, ffi))] #[derive(Debug)] struct Streaming; #[derive(Debug)] @@ -333,13 +306,7 @@ impl fmt::Debug for Incoming { let mut builder = f.debug_tuple("Body"); match self.kind { Kind::Empty => builder.field(&Empty), - #[cfg(any( - all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") - ), - feature = "ffi" - ))] + #[cfg(any(http_client, http_server, ffi))] _ => builder.field(&Streaming), }; @@ -347,7 +314,7 @@ impl fmt::Debug for Incoming { } } -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] impl Sender { /// Check to see if this `Sender` can send more data. pub(crate) fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { @@ -404,14 +371,14 @@ impl Sender { /// This is mostly useful for when trying to send from some other thread /// that doesn't have an async context. If in an async context, prefer /// `send_data()` instead. - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn try_send_data(&mut self, chunk: Bytes) -> Result<(), Bytes> { self.data_tx .try_send(Ok(chunk)) .map_err(|err| err.into_inner().expect("just sent Ok")) } - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn try_send_trailers( &mut self, trailers: HeaderMap, @@ -438,7 +405,7 @@ impl Sender { } } -#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] +#[cfg(any(http1_client, http1_server))] impl fmt::Debug for Sender { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { #[derive(Debug)] @@ -462,11 +429,11 @@ mod tests { use std::task::Poll; use super::{Body, Incoming, SizeHint}; - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] use super::{DecodedLength, Sender}; use http_body_util::BodyExt; - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] #[test] fn test_size_of() { // These are mostly to help catch *accidentally* increasing @@ -496,7 +463,7 @@ mod tests { ); } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] #[test] fn size_hint() { fn eq(body: Incoming, b: SizeHint, note: &str) { @@ -516,7 +483,7 @@ mod tests { ); } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] #[cfg(not(miri))] #[tokio::test] async fn channel_abort() { @@ -528,8 +495,8 @@ mod tests { assert!(err.is_body_write_aborted(), "{:?}", err); } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] - #[cfg(all(not(miri), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] + #[cfg(all(not(miri), http1))] #[tokio::test] async fn channel_abort_when_buffer_is_full() { let (mut tx, mut rx) = Incoming::channel(); @@ -551,7 +518,7 @@ mod tests { assert!(err.is_body_write_aborted(), "{:?}", err); } - #[cfg(feature = "http1")] + #[cfg(http1)] #[test] fn channel_buffers_one() { let (mut tx, _rx) = Incoming::channel(); @@ -563,7 +530,7 @@ mod tests { assert_eq!(chunk2, "chunk 2"); } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] #[cfg(not(miri))] #[tokio::test] async fn channel_empty() { @@ -572,7 +539,7 @@ mod tests { assert!(rx.frame().await.is_none()); } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] #[test] fn channel_ready() { let (mut tx, _rx) = Incoming::new_channel(DecodedLength::CHUNKED, /*wanter = */ false); @@ -582,7 +549,7 @@ mod tests { assert!(tx_ready.poll().is_ready(), "tx is ready immediately"); } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] #[test] fn channel_wanter() { let (mut tx, mut rx) = @@ -605,7 +572,7 @@ mod tests { ); } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] #[test] fn channel_notices_closure() { let (mut tx, rx) = Incoming::new_channel(DecodedLength::CHUNKED, /*wanter = */ true); diff --git a/src/body/length.rs b/src/body/length.rs index e5eab7449f..c293f34b2b 100644 --- a/src/body/length.rs +++ b/src/body/length.rs @@ -3,7 +3,7 @@ use std::fmt; #[derive(Clone, Copy, PartialEq, Eq)] pub(crate) struct DecodedLength(u64); -#[cfg(any(feature = "http1", feature = "http2"))] +#[cfg(any(http1, http2))] impl From> for DecodedLength { fn from(len: Option) -> Self { len.and_then(|len| { @@ -14,7 +14,7 @@ impl From> for DecodedLength { } } -#[cfg(any(feature = "http1", feature = "http2", test))] +#[cfg(any(http1, http2, test))] const MAX_LEN: u64 = u64::MAX - 2; impl DecodedLength { @@ -33,17 +33,14 @@ impl DecodedLength { /// Should only be called if previously confirmed this isn't /// CLOSE_DELIMITED or CHUNKED. #[inline] - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] pub(crate) fn danger_len(self) -> u64 { debug_assert!(self.0 < Self::CHUNKED.0); self.0 } /// Converts to an Option representing a Known or Unknown length. - #[cfg(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") - ))] + #[cfg(any(http_client, http_server))] pub(crate) fn into_opt(self) -> Option { match self { DecodedLength::CHUNKED | DecodedLength::CLOSE_DELIMITED => None, @@ -52,7 +49,7 @@ impl DecodedLength { } /// Checks the `u64` is within the maximum allowed for content-length. - #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(any(http1, http2))] pub(crate) fn checked_new(len: u64) -> Result { if len <= MAX_LEN { Ok(DecodedLength(len)) @@ -62,10 +59,7 @@ impl DecodedLength { } } - #[cfg(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") - ))] + #[cfg(any(http_client, http_server))] pub(crate) fn sub_if(&mut self, amt: u64) { match *self { DecodedLength::CHUNKED | DecodedLength::CLOSE_DELIMITED => (), @@ -80,7 +74,7 @@ impl DecodedLength { /// This includes 0, which of course is an exact known length. /// /// It would return false if "chunked" or otherwise size-unknown. - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] pub(crate) fn is_exact(&self) -> bool { self.0 <= MAX_LEN } diff --git a/src/body/mod.rs b/src/body/mod.rs index 7b71d98be4..4a16fc746d 100644 --- a/src/body/mod.rs +++ b/src/body/mod.rs @@ -26,19 +26,13 @@ pub use http_body::SizeHint; pub use self::incoming::Incoming; -#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] +#[cfg(any(http1_client, http1_server))] pub(crate) use self::incoming::Sender; -#[cfg(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") -))] +#[cfg(any(http_client, http_server))] pub(crate) use self::length::DecodedLength; mod incoming; -#[cfg(all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server") -))] +#[cfg(any(http_client, http_server))] mod length; fn _assert_send_sync() { diff --git a/src/cfg.rs b/src/cfg.rs index 71a5351d21..ac20df9286 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -14,10 +14,7 @@ macro_rules! cfg_feature { macro_rules! cfg_proto { ($($item:item)*) => { cfg_feature! { - #![all( - any(feature = "http1", feature = "http2"), - any(feature = "client", feature = "server"), - )] + #![any(http_client, http_server)] $($item)* } } @@ -27,7 +24,7 @@ cfg_proto! { macro_rules! cfg_client { ($($item:item)*) => { cfg_feature! { - #![feature = "client"] + #![client] $($item)* } } @@ -36,7 +33,7 @@ cfg_proto! { macro_rules! cfg_server { ($($item:item)*) => { cfg_feature! { - #![feature = "server"] + #![server] $($item)* } } diff --git a/src/client/conn/http1.rs b/src/client/conn/http1.rs index ecfe6eb8fb..aa0c85a7f2 100644 --- a/src/client/conn/http1.rs +++ b/src/client/conn/http1.rs @@ -114,7 +114,7 @@ pub struct Builder { h1_title_case_headers: bool, h1_preserve_header_case: bool, h1_max_headers: Option, - #[cfg(feature = "ffi")] + #[cfg(ffi)] h1_preserve_header_order: bool, h1_read_buf_exact_size: Option, h1_max_buf_size: Option, @@ -314,7 +314,7 @@ impl Builder { h1_title_case_headers: false, h1_preserve_header_case: false, h1_max_headers: None, - #[cfg(feature = "ffi")] + #[cfg(ffi)] h1_preserve_header_order: false, h1_max_buf_size: None, } @@ -469,7 +469,7 @@ impl Builder { /// such an extension in any provided `Request`. /// /// Default is false. - #[cfg(feature = "ffi")] + #[cfg(ffi)] pub fn preserve_header_order(&mut self, enabled: bool) -> &mut Builder { self.h1_preserve_header_order = enabled; self @@ -545,7 +545,7 @@ impl Builder { if let Some(max_headers) = opts.h1_max_headers { conn.set_http1_max_headers(max_headers); } - #[cfg(feature = "ffi")] + #[cfg(ffi)] if opts.h1_preserve_header_order { conn.set_preserve_header_order(); } diff --git a/src/client/conn/http2.rs b/src/client/conn/http2.rs index 3db28957b6..f6e9c7b493 100644 --- a/src/client/conn/http2.rs +++ b/src/client/conn/http2.rs @@ -244,7 +244,7 @@ where fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { match ready!(Pin::new(&mut self.inner.1).poll(cx))? { proto::Dispatched::Shutdown => Poll::Ready(Ok(())), - #[cfg(feature = "http1")] + #[cfg(http1)] proto::Dispatched::Upgrade(_pending) => unreachable!("http2 cannot upgrade"), } } diff --git a/src/client/conn/mod.rs b/src/client/conn/mod.rs index f982ae6ddb..0362b9d7b2 100644 --- a/src/client/conn/mod.rs +++ b/src/client/conn/mod.rs @@ -14,9 +14,9 @@ //! //! See the [client guide](https://hyper.rs/guides/1/client/basic/). -#[cfg(feature = "http1")] +#[cfg(http1)] pub mod http1; -#[cfg(feature = "http2")] +#[cfg(http2)] pub mod http2; pub use super::dispatch::TrySendError; diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 4ae41c509d..fe12715723 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -1,16 +1,16 @@ use std::task::{Context, Poll}; -#[cfg(feature = "http2")] +#[cfg(http2)] use std::{future::Future, pin::Pin}; -#[cfg(feature = "http2")] +#[cfg(http2)] use http::{Request, Response}; -#[cfg(feature = "http2")] +#[cfg(http2)] use http_body::Body; -#[cfg(feature = "http2")] +#[cfg(http2)] use pin_project_lite::pin_project; use tokio::sync::{mpsc, oneshot}; -#[cfg(feature = "http2")] +#[cfg(http2)] use crate::{body::Incoming, proto::h2::client::ResponseFutMap}; pub(crate) type RetryPromise = oneshot::Receiver>>; @@ -32,7 +32,7 @@ pub(crate) fn channel() -> (Sender, Receiver) { let (tx, rx) = mpsc::unbounded_channel(); let (giver, taker) = want::new(); let tx = Sender { - #[cfg(feature = "http1")] + #[cfg(http1)] buffered_once: false, giver, inner: tx, @@ -49,7 +49,7 @@ pub(crate) struct Sender { /// One message is always allowed, even if the Receiver hasn't asked /// for it yet. This boolean keeps track of whether we've sent one /// without notice. - #[cfg(feature = "http1")] + #[cfg(http1)] buffered_once: bool, /// The Giver helps watch that the Receiver side has been polled /// when the queue is empty. This helps us know when a request and @@ -64,7 +64,7 @@ pub(crate) struct Sender { /// /// Cannot poll the Giver, but can still use it to determine if the Receiver /// has been dropped. However, this version can be cloned. -#[cfg(feature = "http2")] +#[cfg(http2)] pub(crate) struct UnboundedSender { /// Only used for `is_closed`, since mpsc::UnboundedSender cannot be checked. giver: want::SharedGiver, @@ -72,24 +72,24 @@ pub(crate) struct UnboundedSender { } impl Sender { - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { self.giver .poll_want(cx) .map_err(|_| crate::Error::new_closed()) } - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn is_ready(&self) -> bool { self.giver.is_wanting() } - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn is_closed(&self) -> bool { self.giver.is_canceled() } - #[cfg(feature = "http1")] + #[cfg(http1)] fn can_send(&mut self) -> bool { if self.giver.give() || !self.buffered_once { // If the receiver is ready *now*, then of course we can send. @@ -103,7 +103,7 @@ impl Sender { } } - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn try_send(&mut self, val: T) -> Result, T> { if !self.can_send() { return Err(val); @@ -115,7 +115,7 @@ impl Sender { .map_err(|mut e| (e.0).0.take().expect("envelope not dropped").0) } - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn send(&mut self, val: T) -> Result, T> { if !self.can_send() { return Err(val); @@ -127,7 +127,7 @@ impl Sender { .map_err(|mut e| (e.0).0.take().expect("envelope not dropped").0) } - #[cfg(feature = "http2")] + #[cfg(http2)] pub(crate) fn unbound(self) -> UnboundedSender { UnboundedSender { giver: self.giver.shared(), @@ -136,7 +136,7 @@ impl Sender { } } -#[cfg(feature = "http2")] +#[cfg(http2)] impl UnboundedSender { pub(crate) fn is_ready(&self) -> bool { !self.giver.is_canceled() @@ -163,7 +163,7 @@ impl UnboundedSender { } } -#[cfg(feature = "http2")] +#[cfg(http2)] impl Clone for UnboundedSender { fn clone(&self) -> Self { UnboundedSender { @@ -191,13 +191,13 @@ impl Receiver { } } - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn close(&mut self) { self.taker.cancel(); self.inner.close(); } - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn try_recv(&mut self) -> Option<(T, Callback)> { use futures_util::FutureExt; match self.inner.recv().now_or_never() { @@ -265,7 +265,7 @@ fn dispatch_gone() -> crate::Error { } impl Callback { - #[cfg(feature = "http2")] + #[cfg(http2)] pub(crate) fn is_canceled(&self) -> bool { match *self { Callback::Retry(Some(ref tx)) => tx.is_closed(), @@ -310,7 +310,7 @@ impl TrySendError { } } -#[cfg(feature = "http2")] +#[cfg(http2)] pin_project! { pub struct SendWhen where @@ -324,7 +324,7 @@ pin_project! { } } -#[cfg(feature = "http2")] +#[cfg(http2)] impl Future for SendWhen where B: Body + 'static, @@ -364,7 +364,7 @@ where #[cfg(test)] mod tests { - #[cfg(feature = "nightly")] + #[cfg(nightly)] extern crate test; use std::future::Future; @@ -444,7 +444,7 @@ mod tests { let _ = tx.try_send(Custom(2)).expect("2 ready"); } - #[cfg(feature = "http2")] + #[cfg(http2)] #[test] fn unbounded_sender_doesnt_bound_on_want() { let (tx, rx) = channel::(); @@ -459,7 +459,7 @@ mod tests { let _ = tx.try_send(Custom(4)).unwrap_err(); } - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn giver_queue_throughput(b: &mut test::Bencher) { use crate::{body::Incoming, Request, Response}; @@ -483,7 +483,7 @@ mod tests { }) } - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn giver_queue_not_ready(b: &mut test::Bencher) { let rt = tokio::runtime::Builder::new_current_thread() @@ -498,7 +498,7 @@ mod tests { }) } - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn giver_queue_cancel(b: &mut test::Bencher) { let (_tx, mut rx) = channel::(); diff --git a/src/client/mod.rs b/src/client/mod.rs index 86e3897388..3f51577ebe 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -15,7 +15,7 @@ mod tests; cfg_feature! { - #![any(feature = "http1", feature = "http2")] + #![any(http1, http2)] pub mod conn; pub(super) mod dispatch; diff --git a/src/client/tests.rs b/src/client/tests.rs index 144349e5d7..18d95f258e 100644 --- a/src/client/tests.rs +++ b/src/client/tests.rs @@ -195,7 +195,7 @@ fn checkout_win_allows_connect_future_to_be_pooled() { } } -#[cfg(feature = "nightly")] +#[cfg(nightly)] #[bench] fn bench_http1_get_0b(b: &mut test::Bencher) { let _ = pretty_env_logger::try_init(); @@ -227,7 +227,7 @@ fn bench_http1_get_0b(b: &mut test::Bencher) { }); } -#[cfg(feature = "nightly")] +#[cfg(nightly)] #[bench] fn bench_http1_get_10b(b: &mut test::Bencher) { let _ = pretty_env_logger::try_init(); diff --git a/src/common/date.rs b/src/common/date.rs index 6eae674695..9bc6181d9b 100644 --- a/src/common/date.rs +++ b/src/common/date.rs @@ -3,28 +3,28 @@ use std::fmt::{self, Write}; use std::str; use std::time::{Duration, SystemTime}; -#[cfg(feature = "http2")] +#[cfg(http2)] use http::header::HeaderValue; use httpdate::HttpDate; // "Sun, 06 Nov 1994 08:49:37 GMT".len() pub(crate) const DATE_VALUE_LENGTH: usize = 29; -#[cfg(feature = "http1")] +#[cfg(http1)] pub(crate) fn extend(dst: &mut Vec) { CACHED.with(|cache| { dst.extend_from_slice(cache.borrow().buffer()); }) } -#[cfg(feature = "http1")] +#[cfg(http1)] pub(crate) fn update() { CACHED.with(|cache| { cache.borrow_mut().check(); }) } -#[cfg(feature = "http2")] +#[cfg(http2)] pub(crate) fn update_and_header_value() -> HeaderValue { CACHED.with(|cache| { let mut cache = cache.borrow_mut(); @@ -36,7 +36,7 @@ pub(crate) fn update_and_header_value() -> HeaderValue { struct CachedDate { bytes: [u8; DATE_VALUE_LENGTH], pos: usize, - #[cfg(feature = "http2")] + #[cfg(http2)] header_value: HeaderValue, next_update: SystemTime, } @@ -48,7 +48,7 @@ impl CachedDate { let mut cache = CachedDate { bytes: [0; DATE_VALUE_LENGTH], pos: 0, - #[cfg(feature = "http2")] + #[cfg(http2)] header_value: HeaderValue::from_static(""), next_update: SystemTime::now(), }; @@ -79,13 +79,13 @@ impl CachedDate { self.render_http2(); } - #[cfg(feature = "http2")] + #[cfg(http2)] fn render_http2(&mut self) { self.header_value = HeaderValue::from_bytes(self.buffer()) .expect("Date format should be valid HeaderValue"); } - #[cfg(not(feature = "http2"))] + #[cfg(not(http2))] fn render_http2(&mut self) {} } @@ -102,7 +102,7 @@ impl fmt::Write for CachedDate { mod tests { use super::*; - #[cfg(feature = "nightly")] + #[cfg(nightly)] use test::Bencher; #[test] @@ -110,7 +110,7 @@ mod tests { assert_eq!(DATE_VALUE_LENGTH, "Sun, 06 Nov 1994 08:49:37 GMT".len()); } - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn bench_date_check(b: &mut Bencher) { let mut date = CachedDate::new(); @@ -122,7 +122,7 @@ mod tests { }); } - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn bench_date_render(b: &mut Bencher) { let mut date = CachedDate::new(); diff --git a/src/common/io/mod.rs b/src/common/io/mod.rs index 98c297ca14..7aa7c4899f 100644 --- a/src/common/io/mod.rs +++ b/src/common/io/mod.rs @@ -1,7 +1,7 @@ -#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] +#[cfg(any(http2_client, http2_server))] mod compat; mod rewind; -#[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] +#[cfg(any(http2_client, http2_server))] pub(crate) use self::compat::Compat; pub(crate) use self::rewind::Rewind; diff --git a/src/common/io/rewind.rs b/src/common/io/rewind.rs index c2556f013d..bfe53dbca7 100644 --- a/src/common/io/rewind.rs +++ b/src/common/io/rewind.rs @@ -105,10 +105,7 @@ where } } -#[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2"), -))] +#[cfg(any(http_client, http_server))] #[cfg(test)] mod tests { use super::super::Compat; diff --git a/src/common/mod.rs b/src/common/mod.rs index a0c71385cb..8fc436da3e 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,14 +1,11 @@ -#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] +#[cfg(any(http1_client, http1_server))] pub(crate) mod buf; -#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))] +#[cfg(http_server)] pub(crate) mod date; pub(crate) mod io; -#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] +#[cfg(any(http1_client, http1_server))] pub(crate) mod task; -#[cfg(any( - all(feature = "server", feature = "http1"), - all(any(feature = "client", feature = "server"), feature = "http2"), -))] +#[cfg(any(http_server, http2_client))] pub(crate) mod time; -#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] +#[cfg(any(http1_client, http1_server))] pub(crate) mod watch; diff --git a/src/common/time.rs b/src/common/time.rs index a8d3cc9c85..4ce542a4a5 100644 --- a/src/common/time.rs +++ b/src/common/time.rs @@ -1,7 +1,4 @@ -#[cfg(any( - all(any(feature = "client", feature = "server"), feature = "http2"), - all(feature = "server", feature = "http1"), -))] +#[cfg(any(http_server, http2_client))] use std::time::Duration; use std::{fmt, sync::Arc}; use std::{pin::Pin, time::Instant}; @@ -16,7 +13,7 @@ pub(crate) enum Time { Empty, } -#[cfg(all(feature = "server", feature = "http1"))] +#[cfg(http1_server)] #[derive(Clone, Copy, Debug)] pub(crate) enum Dur { Default(Option), @@ -30,7 +27,7 @@ impl fmt::Debug for Time { } impl Time { - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] pub(crate) fn sleep(&self, duration: Duration) -> Pin> { match *self { Time::Empty => { @@ -40,7 +37,7 @@ impl Time { } } - #[cfg(feature = "http1")] + #[cfg(http1)] pub(crate) fn sleep_until(&self, deadline: Instant) -> Pin> { match *self { Time::Empty => { @@ -59,7 +56,7 @@ impl Time { } } - #[cfg(all(feature = "server", feature = "http1"))] + #[cfg(http1_server)] pub(crate) fn check(&self, dur: Dur, name: &'static str) -> Option { match dur { Dur::Default(Some(dur)) => match self { diff --git a/src/error.rs b/src/error.rs index 48917db970..90dfc0f27b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -42,125 +42,104 @@ pub(super) enum Kind { Parse(Parse), User(User), /// A message reached EOF, but is not complete. - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] IncompleteMessage, /// A connection received a message (or bytes) when not waiting for one. - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] UnexpectedMessage, /// A pending item was dropped before ever being processed. Canceled, /// Indicates a channel (client or body sender) is closed. - #[cfg(any( - all(feature = "http1", any(feature = "client", feature = "server")), - all(feature = "http2", feature = "client") - ))] + #[cfg(any(http_client, http1_server))] ChannelClosed, /// An `io::Error` that occurred while trying to read or write to a network stream. - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] Io, /// User took too long to send headers - #[cfg(all(feature = "http1", feature = "server"))] + #[cfg(http1_server)] HeaderTimeout, /// Error while reading a body from connection. - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] Body, /// Error while writing a body to connection. - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] BodyWrite, /// Error calling AsyncWrite::shutdown() - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Shutdown, /// A general error from h2. - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] Http2, } #[derive(Debug)] pub(super) enum Parse { Method, - #[cfg(feature = "http1")] + #[cfg(http1)] Version, - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] VersionH2, Uri, - #[cfg(all(feature = "http1", feature = "server"))] + #[cfg(http1_server)] UriTooLong, - #[cfg(feature = "http1")] + #[cfg(http1)] Header(Header), - #[cfg(any(feature = "http1", feature = "http2"))] - #[cfg_attr(feature = "http2", allow(unused))] + #[cfg(any(http1, http2))] + #[cfg_attr(http2, allow(unused))] TooLarge, Status, - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Internal, } #[derive(Debug)] -#[cfg(feature = "http1")] +#[cfg(http1)] pub(super) enum Header { Token, - #[cfg(any(feature = "client", feature = "server"))] + #[cfg(any(client, server))] ContentLengthInvalid, - #[cfg(feature = "server")] + #[cfg(server)] TransferEncodingInvalid, - #[cfg(any(feature = "client", feature = "server"))] + #[cfg(any(client, server))] TransferEncodingUnexpected, } #[derive(Debug)] pub(super) enum User { /// Error calling user's Body::poll_data(). - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] Body, /// The user aborted writing of the outgoing body. - #[cfg(any( - all(feature = "http1", any(feature = "client", feature = "server")), - feature = "ffi" - ))] + #[cfg(any(http1_client, http1_server, ffi))] BodyWriteAborted, /// Error from future of user's Service. - #[cfg(any( - all(any(feature = "client", feature = "server"), feature = "http1"), - all(feature = "server", feature = "http2") - ))] + #[cfg(any(http1_client, http_server))] Service, /// User tried to send a certain header in an unexpected context. /// /// For example, sending both `content-length` and `transfer-encoding`. - #[cfg(any(feature = "http1", feature = "http2"))] - #[cfg(feature = "server")] + #[cfg(any(http1, http2))] + #[cfg(server)] UnexpectedHeader, /// User tried to respond with a 1xx (not 101) response code. - #[cfg(feature = "http1")] - #[cfg(feature = "server")] + #[cfg(http1)] + #[cfg(server)] UnsupportedStatusCode, /// User tried polling for an upgrade that doesn't exist. NoUpgrade, /// User polled for an upgrade, but low-level API is not using upgrades. - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] ManualUpgrade, /// The dispatch task is gone. - #[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))] + #[cfg(any(http_client))] DispatchGone, /// User aborted in an FFI callback. - #[cfg(feature = "ffi")] + #[cfg(ffi)] AbortedByCallback, } @@ -175,7 +154,7 @@ impl Error { } /// Returns true if this was an HTTP parse error caused by a message that was too large. - #[cfg(all(feature = "http1", feature = "server"))] + #[cfg(http1_server)] pub fn is_parse_too_large(&self) -> bool { matches!( self.inner.kind, @@ -201,46 +180,34 @@ impl Error { /// Returns true if a sender's channel is closed. pub fn is_closed(&self) -> bool { - #[cfg(not(any( - all(feature = "http1", any(feature = "client", feature = "server")), - all(feature = "http2", feature = "client") - )))] + #[cfg(not(any(http_client, http1_server)))] return false; - #[cfg(any( - all(feature = "http1", any(feature = "client", feature = "server")), - all(feature = "http2", feature = "client") - ))] + #[cfg(any(http_client, http1_server))] matches!(self.inner.kind, Kind::ChannelClosed) } /// Returns true if the connection closed before a message could complete. pub fn is_incomplete_message(&self) -> bool { - #[cfg(not(all(any(feature = "client", feature = "server"), feature = "http1")))] + #[cfg(not(any(http1_client, http1_server)))] return false; - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] matches!(self.inner.kind, Kind::IncompleteMessage) } /// Returns true if the body write was aborted. pub fn is_body_write_aborted(&self) -> bool { - #[cfg(not(any( - all(feature = "http1", any(feature = "client", feature = "server")), - feature = "ffi" - )))] + #[cfg(not(any(http1_client, http1_server, ffi)))] return false; - #[cfg(any( - all(feature = "http1", any(feature = "client", feature = "server")), - feature = "ffi" - ))] + #[cfg(any(http1_client, http1_server, ffi))] matches!(self.inner.kind, Kind::User(User::BodyWriteAborted)) } /// Returns true if the error was caused by a timeout. pub fn is_timeout(&self) -> bool { - #[cfg(all(feature = "http1", feature = "server"))] + #[cfg(http1_server)] if matches!(self.inner.kind, Kind::HeaderTimeout) { return true; } @@ -258,7 +225,7 @@ impl Error { self } - #[cfg(any(all(feature = "http1", feature = "server"), feature = "ffi"))] + #[cfg(any(http1_server, ffi))] pub(super) fn kind(&self) -> &Kind { &self.inner.kind } @@ -276,7 +243,7 @@ impl Error { None } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] pub(super) fn h2_reason(&self) -> h2::Reason { // Find an h2::Reason somewhere in the cause stack, if it exists, // otherwise assume an INTERNAL_ERROR. @@ -289,62 +256,47 @@ impl Error { Error::new(Kind::Canceled) } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] pub(super) fn new_incomplete() -> Error { Error::new(Kind::IncompleteMessage) } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] pub(super) fn new_too_large() -> Error { Error::new(Kind::Parse(Parse::TooLarge)) } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] pub(super) fn new_version_h2() -> Error { Error::new(Kind::Parse(Parse::VersionH2)) } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] pub(super) fn new_unexpected_message() -> Error { Error::new(Kind::UnexpectedMessage) } - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] pub(super) fn new_io(cause: std::io::Error) -> Error { Error::new(Kind::Io).with(cause) } - #[cfg(any( - all(feature = "http1", any(feature = "client", feature = "server")), - all(feature = "http2", feature = "client") - ))] + #[cfg(any(http_client, http1_server))] pub(super) fn new_closed() -> Error { Error::new(Kind::ChannelClosed) } - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] pub(super) fn new_body>(cause: E) -> Error { Error::new(Kind::Body).with(cause) } - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] pub(super) fn new_body_write>(cause: E) -> Error { Error::new(Kind::BodyWrite).with(cause) } - #[cfg(any( - all(feature = "http1", any(feature = "client", feature = "server")), - feature = "ffi" - ))] + #[cfg(any(http1_client, http1_server, ffi))] pub(super) fn new_body_write_aborted() -> Error { Error::new(Kind::User(User::BodyWriteAborted)) } @@ -353,19 +305,19 @@ impl Error { Error::new(Kind::User(user)) } - #[cfg(any(feature = "http1", feature = "http2"))] - #[cfg(feature = "server")] + #[cfg(any(http1, http2))] + #[cfg(server)] pub(super) fn new_user_header() -> Error { Error::new_user(User::UnexpectedHeader) } - #[cfg(all(feature = "http1", feature = "server"))] + #[cfg(http1_server)] pub(super) fn new_header_timeout() -> Error { Error::new(Kind::HeaderTimeout) } - #[cfg(feature = "http1")] - #[cfg(feature = "server")] + #[cfg(http1)] + #[cfg(server)] pub(super) fn new_user_unsupported_status_code() -> Error { Error::new_user(User::UnsupportedStatusCode) } @@ -374,43 +326,37 @@ impl Error { Error::new_user(User::NoUpgrade) } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] pub(super) fn new_user_manual_upgrade() -> Error { Error::new_user(User::ManualUpgrade) } - #[cfg(any( - all(any(feature = "client", feature = "server"), feature = "http1"), - all(feature = "server", feature = "http2") - ))] + #[cfg(any(http1_client, http_server))] pub(super) fn new_user_service>(cause: E) -> Error { Error::new_user(User::Service).with(cause) } - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] pub(super) fn new_user_body>(cause: E) -> Error { Error::new_user(User::Body).with(cause) } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] pub(super) fn new_shutdown(cause: std::io::Error) -> Error { Error::new(Kind::Shutdown).with(cause) } - #[cfg(feature = "ffi")] + #[cfg(ffi)] pub(super) fn new_user_aborted_by_callback() -> Error { Error::new_user(User::AbortedByCallback) } - #[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))] + #[cfg(http_client)] pub(super) fn new_user_dispatch_gone() -> Error { Error::new(Kind::User(User::DispatchGone)) } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] pub(super) fn new_h2(cause: ::h2::Error) -> Error { if cause.is_io() { Error::new_io(cause.into_io().expect("h2::Error::is_io")) @@ -422,95 +368,74 @@ impl Error { fn description(&self) -> &str { match self.inner.kind { Kind::Parse(Parse::Method) => "invalid HTTP method parsed", - #[cfg(feature = "http1")] + #[cfg(http1)] Kind::Parse(Parse::Version) => "invalid HTTP version parsed", - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Kind::Parse(Parse::VersionH2) => "invalid HTTP version parsed (found HTTP2 preface)", Kind::Parse(Parse::Uri) => "invalid URI", - #[cfg(all(feature = "http1", feature = "server"))] + #[cfg(http1_server)] Kind::Parse(Parse::UriTooLong) => "URI too long", - #[cfg(feature = "http1")] + #[cfg(http1)] Kind::Parse(Parse::Header(Header::Token)) => "invalid HTTP header parsed", - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Kind::Parse(Parse::Header(Header::ContentLengthInvalid)) => { "invalid content-length parsed" } - #[cfg(all(feature = "http1", feature = "server"))] + #[cfg(http1_server)] Kind::Parse(Parse::Header(Header::TransferEncodingInvalid)) => { "invalid transfer-encoding parsed" } - #[cfg(all(feature = "http1", any(feature = "client", feature = "server")))] + #[cfg(any(http1_client, http1_server))] Kind::Parse(Parse::Header(Header::TransferEncodingUnexpected)) => { "unexpected transfer-encoding parsed" } - #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(any(http1, http2))] Kind::Parse(Parse::TooLarge) => "message head is too large", Kind::Parse(Parse::Status) => "invalid HTTP status-code parsed", - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Kind::Parse(Parse::Internal) => { "internal error inside Hyper and/or its dependencies, please report" } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Kind::IncompleteMessage => "connection closed before message completed", - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Kind::UnexpectedMessage => "received unexpected message from connection", - #[cfg(any( - all(feature = "http1", any(feature = "client", feature = "server")), - all(feature = "http2", feature = "client") - ))] + #[cfg(any(http_client, http1_server))] Kind::ChannelClosed => "channel closed", Kind::Canceled => "operation was canceled", - #[cfg(all(feature = "http1", feature = "server"))] + #[cfg(http1_server)] Kind::HeaderTimeout => "read header from client timeout", - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] Kind::Body => "error reading a body from connection", - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] Kind::BodyWrite => "error writing a body to connection", - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Kind::Shutdown => "error shutting down connection", - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] Kind::Http2 => "http2 error", - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] Kind::Io => "connection error", - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] Kind::User(User::Body) => "error from user's Body stream", - #[cfg(any( - all(feature = "http1", any(feature = "client", feature = "server")), - feature = "ffi" - ))] + #[cfg(any(http1_client, http1_server, ffi))] Kind::User(User::BodyWriteAborted) => "user body write aborted", - #[cfg(any( - all(any(feature = "client", feature = "server"), feature = "http1"), - all(feature = "server", feature = "http2") - ))] + #[cfg(any(http_client, http1_server))] Kind::User(User::Service) => "error from user's Service", - #[cfg(any(feature = "http1", feature = "http2"))] - #[cfg(feature = "server")] + #[cfg(any(http1, http2))] + #[cfg(server)] Kind::User(User::UnexpectedHeader) => "user sent unexpected header", - #[cfg(feature = "http1")] - #[cfg(feature = "server")] + #[cfg(http1)] + #[cfg(server)] Kind::User(User::UnsupportedStatusCode) => { "response has 1xx status code, not supported by server" } Kind::User(User::NoUpgrade) => "no upgrade available", - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] Kind::User(User::ManualUpgrade) => "upgrade expected but low level API in use", - #[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))] + #[cfg(http_client)] Kind::User(User::DispatchGone) => "dispatch task is gone", - #[cfg(feature = "ffi")] + #[cfg(ffi)] Kind::User(User::AbortedByCallback) => "operation aborted by an application callback", } } @@ -549,25 +474,25 @@ impl From for Error { } } -#[cfg(feature = "http1")] +#[cfg(http1)] impl Parse { - #[cfg(any(feature = "client", feature = "server"))] + #[cfg(any(client, server))] pub(crate) fn content_length_invalid() -> Self { Parse::Header(Header::ContentLengthInvalid) } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn transfer_encoding_invalid() -> Self { Parse::Header(Header::TransferEncodingInvalid) } - #[cfg(any(feature = "client", feature = "server"))] + #[cfg(any(client, server))] pub(crate) fn transfer_encoding_unexpected() -> Self { Parse::Header(Header::TransferEncodingUnexpected) } } -#[cfg(feature = "http1")] +#[cfg(http1)] impl From for Parse { fn from(err: httparse::Error) -> Parse { match err { @@ -633,21 +558,21 @@ mod tests { assert_eq!(mem::size_of::(), mem::size_of::()); } - #[cfg(feature = "http2")] + #[cfg(http2)] #[test] fn h2_reason_unknown() { let closed = Error::new_closed(); assert_eq!(closed.h2_reason(), h2::Reason::INTERNAL_ERROR); } - #[cfg(feature = "http2")] + #[cfg(http2)] #[test] fn h2_reason_one_level() { let body_err = Error::new_user_body(h2::Error::from(h2::Reason::ENHANCE_YOUR_CALM)); assert_eq!(body_err.h2_reason(), h2::Reason::ENHANCE_YOUR_CALM); } - #[cfg(feature = "http2")] + #[cfg(http2)] #[test] fn h2_reason_nested() { let recvd = Error::new_h2(h2::Error::from(h2::Reason::HTTP_1_1_REQUIRED)); diff --git a/src/ext/h1_reason_phrase.rs b/src/ext/h1_reason_phrase.rs index adb4363689..eebaa09692 100644 --- a/src/ext/h1_reason_phrase.rs +++ b/src/ext/h1_reason_phrase.rs @@ -11,7 +11,7 @@ use bytes::Bytes; /// the response will not contain a `ReasonPhrase`. /// /// ```no_run -/// # #[cfg(all(feature = "tcp", feature = "client", feature = "http1"))] +/// # #[cfg(all(feature = "tcp", client, http1))] /// # async fn fake_fetch() -> hyper::Result<()> { /// use hyper::{Client, Uri}; /// use hyper::ext::ReasonPhrase; @@ -53,7 +53,7 @@ impl ReasonPhrase { /// /// Use with care; invalid bytes in a reason phrase can cause serious security problems if /// emitted in a response. - #[cfg(feature = "client")] + #[cfg(client)] pub(crate) fn from_bytes_unchecked(reason: Bytes) -> Self { Self(reason) } diff --git a/src/ext/mod.rs b/src/ext/mod.rs index da28da64a5..04e4a1b63c 100644 --- a/src/ext/mod.rs +++ b/src/ext/mod.rs @@ -1,34 +1,31 @@ //! HTTP extensions. -#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] +#[cfg(any(http1_client, http1_server))] use bytes::Bytes; -#[cfg(any( - all(any(feature = "client", feature = "server"), feature = "http1"), - feature = "ffi" -))] +#[cfg(any(http1_client, http1_server, ffi))] use http::header::HeaderName; -#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] +#[cfg(any(http1_client, http1_server))] use http::header::{HeaderMap, IntoHeaderName, ValueIter}; -#[cfg(feature = "ffi")] +#[cfg(ffi)] use std::collections::HashMap; -#[cfg(feature = "http2")] +#[cfg(http2)] use std::fmt; -#[cfg(any(feature = "http1", feature = "ffi"))] +#[cfg(any(http1, ffi))] mod h1_reason_phrase; -#[cfg(any(feature = "http1", feature = "ffi"))] +#[cfg(any(http1, ffi))] pub use h1_reason_phrase::ReasonPhrase; -#[cfg(all(feature = "http1", feature = "client"))] +#[cfg(http1_client)] mod informational; -#[cfg(all(feature = "http1", feature = "client"))] +#[cfg(http1_client)] pub use informational::on_informational; -#[cfg(all(feature = "http1", feature = "client"))] +#[cfg(http1_client)] pub(crate) use informational::OnInformational; -#[cfg(all(feature = "http1", feature = "client", feature = "ffi"))] +#[cfg(all(http1_client, ffi))] pub(crate) use informational::{on_informational_raw, OnInformationalCallback}; -#[cfg(feature = "http2")] +#[cfg(http2)] /// Represents the `:protocol` pseudo-header used by /// the [Extended CONNECT Protocol]. /// @@ -38,7 +35,7 @@ pub struct Protocol { inner: h2::ext::Protocol, } -#[cfg(feature = "http2")] +#[cfg(http2)] impl Protocol { /// Converts a static string to a protocol name. pub const fn from_static(value: &'static str) -> Self { @@ -52,18 +49,18 @@ impl Protocol { self.inner.as_str() } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn from_inner(inner: h2::ext::Protocol) -> Self { Self { inner } } - #[cfg(all(feature = "client", feature = "http2"))] + #[cfg(http2_client)] pub(crate) fn into_inner(self) -> h2::ext::Protocol { self.inner } } -#[cfg(feature = "http2")] +#[cfg(http2)] impl<'a> From<&'a str> for Protocol { fn from(value: &'a str) -> Self { Self { @@ -72,14 +69,14 @@ impl<'a> From<&'a str> for Protocol { } } -#[cfg(feature = "http2")] +#[cfg(http2)] impl AsRef<[u8]> for Protocol { fn as_ref(&self) -> &[u8] { self.inner.as_ref() } } -#[cfg(feature = "http2")] +#[cfg(http2)] impl fmt::Debug for Protocol { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.inner.fmt(f) @@ -107,15 +104,15 @@ impl fmt::Debug for Protocol { /// ``` /// /// [`preserve_header_case`]: /client/struct.Client.html#method.preserve_header_case -#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] +#[cfg(any(http1_client, http1_server))] #[derive(Clone, Debug)] pub(crate) struct HeaderCaseMap(HeaderMap); -#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] +#[cfg(any(http1_client, http1_server))] impl HeaderCaseMap { /// Returns a view of all spellings associated with that header name, /// in the order they were found. - #[cfg(feature = "client")] + #[cfg(client)] pub(crate) fn get_all<'a>( &'a self, name: &HeaderName, @@ -125,22 +122,22 @@ impl HeaderCaseMap { /// Returns a view of all spellings associated with that header name, /// in the order they were found. - #[cfg(any(feature = "client", feature = "server"))] + #[cfg(any(client, server))] pub(crate) fn get_all_internal(&self, name: &HeaderName) -> ValueIter<'_, Bytes> { self.0.get_all(name).into_iter() } - #[cfg(any(feature = "client", feature = "server"))] + #[cfg(any(client, server))] pub(crate) fn default() -> Self { Self(Default::default()) } - #[cfg(any(test, feature = "ffi"))] + #[cfg(any(test, ffi))] pub(crate) fn insert(&mut self, name: HeaderName, orig: Bytes) { self.0.insert(name, orig); } - #[cfg(any(feature = "client", feature = "server"))] + #[cfg(any(client, server))] pub(crate) fn append(&mut self, name: N, orig: Bytes) where N: IntoHeaderName, @@ -149,7 +146,7 @@ impl HeaderCaseMap { } } -#[cfg(feature = "ffi")] +#[cfg(ffi)] #[derive(Clone, Debug)] /// Hashmap pub(crate) struct OriginalHeaderOrder { @@ -164,7 +161,7 @@ pub(crate) struct OriginalHeaderOrder { entry_order: Vec<(HeaderName, usize)>, } -#[cfg(all(feature = "http1", feature = "ffi"))] +#[cfg(all(http1, ffi))] impl OriginalHeaderOrder { pub(crate) fn default() -> Self { OriginalHeaderOrder { diff --git a/src/ffi/client.rs b/src/ffi/client.rs index 63b03d874a..18d2456897 100644 --- a/src/ffi/client.rs +++ b/src/ffi/client.rs @@ -73,9 +73,9 @@ pub struct hyper_clientconn { } enum Tx { - #[cfg(feature = "http1")] + #[cfg(http1)] Http1(conn::http1::SendRequest), - #[cfg(feature = "http2")] + #[cfg(http2)] Http2(conn::http2::SendRequest), } @@ -98,7 +98,7 @@ ffi_fn! { let io = non_null! { Box::from_raw(io) ?= ptr::null_mut() }; Box::into_raw(hyper_task::boxed(async move { - #[cfg(feature = "http2")] + #[cfg(http2)] { if options.http2 { return conn::http2::Builder::new(options.exec.clone()) @@ -243,14 +243,14 @@ ffi_fn! { /// /// Pass `0` to disable, `1` to enable. fn hyper_clientconn_options_http2(opts: *mut hyper_clientconn_options, enabled: c_int) -> hyper_code { - #[cfg(feature = "http2")] + #[cfg(http2)] { let opts = non_null! { &mut *opts ?= hyper_code::HYPERE_INVALID_ARG }; opts.http2 = enabled != 0; hyper_code::HYPERE_OK } - #[cfg(not(feature = "http2"))] + #[cfg(not(http2))] { drop(opts); drop(enabled); diff --git a/src/ffi/error.rs b/src/ffi/error.rs index cc289ed7b7..5cf30634db 100644 --- a/src/ffi/error.rs +++ b/src/ffi/error.rs @@ -29,7 +29,7 @@ pub enum hyper_code { /// Aborted by a user supplied callback. HYPERE_ABORTED_BY_CALLBACK, /// An optional hyper feature was not enabled. - #[cfg_attr(feature = "http2", allow(unused))] + #[cfg_attr(http2, allow(unused))] HYPERE_FEATURE_NOT_ENABLED, /// The peer sent an HTTP message that could not be parsed. HYPERE_INVALID_PEER_MESSAGE, diff --git a/src/ffi/http_types.rs b/src/ffi/http_types.rs index 3dc4a2549d..f2bdcb0b1f 100644 --- a/src/ffi/http_types.rs +++ b/src/ffi/http_types.rs @@ -268,7 +268,7 @@ ffi_fn! { /// be valid after the callback finishes. You must copy any data you wish /// to persist. fn hyper_request_on_informational(req: *mut hyper_request, callback: hyper_request_on_informational_callback, data: *mut c_void) -> hyper_code { - #[cfg(feature = "client")] + #[cfg(client)] { let ext = OnInformational { func: callback, @@ -278,7 +278,7 @@ ffi_fn! { crate::ext::on_informational_raw(&mut req.0, ext); hyper_code::HYPERE_OK } - #[cfg(not(feature = "client"))] + #[cfg(not(client))] { drop((req, callback, data)); hyper_code::HYPERE_FEATURE_NOT_ENABLED @@ -575,7 +575,7 @@ unsafe fn raw_name_value( // ===== impl OnInformational ===== -#[cfg(feature = "client")] +#[cfg(client)] impl crate::ext::OnInformationalCallback for OnInformational { fn on_informational(&self, res: http::Response<()>) { let res = res.map(|()| IncomingBody::empty()); @@ -637,7 +637,7 @@ mod tests { } } - #[cfg(all(feature = "http1", feature = "ffi"))] + #[cfg(all(http1, ffi))] #[test] fn test_headers_foreach_order_preserved() { let mut headers = hyper_headers::default(); diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index cdcbc4822d..71a614e257 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -33,7 +33,7 @@ // the `Cargo.toml`. // // But for now, give a clear message that this compile error is expected. -#[cfg(not(all(feature = "client", feature = "http1")))] +#[cfg(not(http1_client))] compile_error!("The `ffi` feature currently requires the `client` and `http1` features."); #[cfg(not(hyper_unstable_ffi))] diff --git a/src/headers.rs b/src/headers.rs index 8bebdb9bfa..f3b0081ca8 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -1,25 +1,25 @@ -#[cfg(all(feature = "client", feature = "http1"))] +#[cfg(http1_client)] use bytes::BytesMut; use http::header::HeaderValue; -#[cfg(all(feature = "http2", feature = "client"))] +#[cfg(http2_client)] use http::Method; -#[cfg(any(feature = "client", all(feature = "server", feature = "http2")))] +#[cfg(any(client, http2_server))] use http::{ header::{ValueIter, CONTENT_LENGTH}, HeaderMap, }; -#[cfg(feature = "http1")] +#[cfg(http1)] pub(super) fn connection_keep_alive(value: &HeaderValue) -> bool { connection_has(value, "keep-alive") } -#[cfg(feature = "http1")] +#[cfg(http1)] pub(super) fn connection_close(value: &HeaderValue) -> bool { connection_has(value, "close") } -#[cfg(feature = "http1")] +#[cfg(http1)] fn connection_has(value: &HeaderValue, needle: &str) -> bool { if let Ok(s) = value.to_str() { for val in s.split(',') { @@ -31,17 +31,17 @@ fn connection_has(value: &HeaderValue, needle: &str) -> bool { false } -#[cfg(all(feature = "http1", feature = "server"))] +#[cfg(http1_server)] pub(super) fn content_length_parse(value: &HeaderValue) -> Option { from_digits(value.as_bytes()) } -#[cfg(any(feature = "client", all(feature = "server", feature = "http2")))] +#[cfg(any(client, http2_server))] pub(super) fn content_length_parse_all(headers: &HeaderMap) -> Option { content_length_parse_all_values(headers.get_all(CONTENT_LENGTH).into_iter()) } -#[cfg(any(feature = "client", all(feature = "server", feature = "http2")))] +#[cfg(any(client, http2_server))] pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>) -> Option { // If multiple Content-Length headers were sent, everything can still // be alright if they all contain the same value, and all parse @@ -96,7 +96,7 @@ fn from_digits(bytes: &[u8]) -> Option { Some(result) } -#[cfg(all(feature = "http2", feature = "client"))] +#[cfg(http2_client)] pub(super) fn method_has_defined_payload_semantics(method: &Method) -> bool { !matches!( *method, @@ -104,19 +104,19 @@ pub(super) fn method_has_defined_payload_semantics(method: &Method) -> bool { ) } -#[cfg(feature = "http2")] +#[cfg(http2)] pub(super) fn set_content_length_if_missing(headers: &mut HeaderMap, len: u64) { headers .entry(CONTENT_LENGTH) .or_insert_with(|| HeaderValue::from(len)); } -#[cfg(all(feature = "client", feature = "http1"))] +#[cfg(http1_client)] pub(super) fn transfer_encoding_is_chunked(headers: &HeaderMap) -> bool { is_chunked(headers.get_all(http::header::TRANSFER_ENCODING).into_iter()) } -#[cfg(all(feature = "client", feature = "http1"))] +#[cfg(http1_client)] pub(super) fn is_chunked(mut encodings: ValueIter<'_, HeaderValue>) -> bool { // chunked must always be the last encoding, according to spec if let Some(line) = encodings.next_back() { @@ -126,7 +126,7 @@ pub(super) fn is_chunked(mut encodings: ValueIter<'_, HeaderValue>) -> bool { false } -#[cfg(feature = "http1")] +#[cfg(http1)] pub(super) fn is_chunked_(value: &HeaderValue) -> bool { // chunked must always be the last encoding, according to spec if let Ok(s) = value.to_str() { @@ -138,7 +138,7 @@ pub(super) fn is_chunked_(value: &HeaderValue) -> bool { false } -#[cfg(all(feature = "client", feature = "http1"))] +#[cfg(http1_client)] pub(super) fn add_chunked(mut entry: http::header::OccupiedEntry<'_, HeaderValue>) { const CHUNKED: &str = "chunked"; diff --git a/src/lib.rs b/src/lib.rs index 4683fd6597..958cdf97ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,9 @@ #![deny(missing_docs)] #![deny(missing_debug_implementations)] #![cfg_attr(test, deny(rust_2018_idioms))] -#![cfg_attr(all(test, feature = "full"), deny(unreachable_pub))] -#![cfg_attr(all(test, feature = "full"), deny(warnings))] -#![cfg_attr(all(test, feature = "nightly"), feature(test))] +#![cfg_attr(all(test, full), deny(unreachable_pub))] +#![cfg_attr(all(test, full), deny(warnings))] +#![cfg_attr(all(test, nightly), feature(test))] #![cfg_attr(docsrs, feature(doc_cfg))] //! # hyper @@ -93,7 +93,7 @@ #[doc(hidden)] pub use http; -#[cfg(all(test, feature = "nightly"))] +#[cfg(all(test, nightly))] extern crate test; #[doc(no_inline)] @@ -117,8 +117,8 @@ pub mod rt; pub mod service; pub mod upgrade; -#[cfg(feature = "ffi")] -#[cfg_attr(docsrs, doc(cfg(all(feature = "ffi", hyper_unstable_ffi))))] +#[cfg(ffi)] +#[cfg_attr(docsrs, doc(cfg(all(ffi, hyper_unstable_ffi))))] pub mod ffi; cfg_proto! { @@ -127,13 +127,13 @@ cfg_proto! { } cfg_feature! { - #![feature = "client"] + #![client] pub mod client; } cfg_feature! { - #![feature = "server"] + #![server] pub mod server; } diff --git a/src/mock.rs b/src/mock.rs index 1dd57de319..6f56601e13 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -1,37 +1,37 @@ // FIXME: re-implement tests with `async/await` /* -#[cfg(feature = "runtime")] +#[cfg(runtime)] use std::collections::HashMap; use std::cmp; use std::io::{self, Read, Write}; -#[cfg(feature = "runtime")] +#[cfg(runtime)] use std::sync::{Arc, Mutex}; use bytes::Buf; use futures::{Async, Poll}; -#[cfg(feature = "runtime")] +#[cfg(runtime)] use futures::Future; use futures::task::{self, Task}; use tokio_io::{AsyncRead, AsyncWrite}; -#[cfg(feature = "runtime")] +#[cfg(runtime)] use crate::client::connect::{Connect, Connected, Destination}; -#[cfg(feature = "runtime")] +#[cfg(runtime)] pub struct Duplex { inner: Arc>, } -#[cfg(feature = "runtime")] +#[cfg(runtime)] struct DuplexInner { handle_read_task: Option, read: AsyncIo, write: AsyncIo, } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl Duplex { pub(crate) fn channel() -> (Duplex, DuplexHandle) { let mut inner = DuplexInner { @@ -56,14 +56,14 @@ impl Duplex { } } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl Read for Duplex { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.inner.lock().unwrap().read.read(buf) } } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl Write for Duplex { fn write(&mut self, buf: &[u8]) -> io::Result { let mut inner = self.inner.lock().unwrap(); @@ -80,11 +80,11 @@ impl Write for Duplex { } } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl AsyncRead for Duplex { } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl AsyncWrite for Duplex { fn shutdown(&mut self) -> Poll<(), io::Error> { Ok(().into()) @@ -99,12 +99,12 @@ impl AsyncWrite for Duplex { } } -#[cfg(feature = "runtime")] +#[cfg(runtime)] pub struct DuplexHandle { inner: Arc>, } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl DuplexHandle { pub fn read(&self, buf: &mut [u8]) -> Poll { let mut inner = self.inner.lock().unwrap(); @@ -131,7 +131,7 @@ impl DuplexHandle { } } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl Drop for DuplexHandle { fn drop(&mut self) { trace!("mock duplex handle drop"); @@ -143,19 +143,19 @@ impl Drop for DuplexHandle { } } -#[cfg(feature = "runtime")] +#[cfg(runtime)] type BoxedConnectFut = Box + Send>; -#[cfg(feature = "runtime")] +#[cfg(runtime)] #[derive(Clone)] pub struct MockConnector { mocks: Arc>, } -#[cfg(feature = "runtime")] +#[cfg(runtime)] struct MockedConnections(HashMap>); -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl MockConnector { pub fn new() -> MockConnector { MockConnector { @@ -195,7 +195,7 @@ impl MockConnector { } } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl Connect for MockConnector { type Transport = Duplex; type Error = io::Error; @@ -217,7 +217,7 @@ impl Connect for MockConnector { } -#[cfg(feature = "runtime")] +#[cfg(runtime)] impl Drop for MockedConnections { fn drop(&mut self) { if !::std::thread::panicking() { diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs index bea8faa221..7e5cba22d6 100644 --- a/src/proto/h1/conn.rs +++ b/src/proto/h1/conn.rs @@ -1,11 +1,11 @@ use std::fmt; -#[cfg(feature = "server")] +#[cfg(server)] use std::future::Future; use std::io; use std::marker::{PhantomData, Unpin}; use std::pin::Pin; use std::task::{Context, Poll}; -#[cfg(feature = "server")] +#[cfg(server)] use std::time::{Duration, Instant}; use crate::rt::{Read, Write}; @@ -19,11 +19,11 @@ use httparse::ParserConfig; use super::io::Buffered; use super::{Decoder, Encode, EncodedBuf, Encoder, Http1Transaction, ParseContext, Wants}; use crate::body::DecodedLength; -#[cfg(feature = "server")] +#[cfg(server)] use crate::common::time::Time; use crate::headers; use crate::proto::{BodyLength, MessageHead}; -#[cfg(feature = "server")] +#[cfg(server)] use crate::rt::Sleep; const H2_PREFACE: &[u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"; @@ -58,22 +58,22 @@ where method: None, h1_parser_config: ParserConfig::default(), h1_max_headers: None, - #[cfg(feature = "server")] + #[cfg(server)] h1_header_read_timeout: None, - #[cfg(feature = "server")] + #[cfg(server)] h1_header_read_timeout_fut: None, - #[cfg(feature = "server")] + #[cfg(server)] h1_header_read_timeout_running: false, - #[cfg(feature = "server")] + #[cfg(server)] date_header: true, - #[cfg(feature = "server")] + #[cfg(server)] timer: Time::Empty, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, title_case_headers: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: None, notify_read: false, reading: Reading::Init, @@ -88,12 +88,12 @@ where } } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn set_timer(&mut self, timer: Time) { self.state.timer = timer; } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn set_flush_pipeline(&mut self, enabled: bool) { self.io.set_flush_pipeline(enabled); } @@ -106,7 +106,7 @@ where self.io.set_max_buf_size(max); } - #[cfg(feature = "client")] + #[cfg(client)] pub(crate) fn set_read_buf_exact_size(&mut self, sz: usize) { self.io.set_read_buf_exact_size(sz); } @@ -127,12 +127,12 @@ where self.state.preserve_header_case = true; } - #[cfg(feature = "ffi")] + #[cfg(ffi)] pub(crate) fn set_preserve_header_order(&mut self) { self.state.preserve_header_order = true; } - #[cfg(feature = "client")] + #[cfg(client)] pub(crate) fn set_h09_responses(&mut self) { self.state.h09_responses = true; } @@ -141,17 +141,17 @@ where self.state.h1_max_headers = Some(val); } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn set_http1_header_read_timeout(&mut self, val: Duration) { self.state.h1_header_read_timeout = Some(val); } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn set_allow_half_close(&mut self) { self.state.allow_half_close = true; } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn disable_date_header(&mut self) { self.state.date_header = false; } @@ -191,7 +191,7 @@ where ) } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn has_initial_read_write_state(&self) -> bool { matches!(self.state.reading, Reading::Init) && matches!(self.state.writing, Writing::Init) @@ -215,7 +215,7 @@ where debug_assert!(self.can_read_head()); trace!("Conn::read_head"); - #[cfg(feature = "server")] + #[cfg(server)] if !self.state.h1_header_read_timeout_running { if let Some(h1_header_read_timeout) = self.state.h1_header_read_timeout { let deadline = Instant::now() + h1_header_read_timeout; @@ -242,17 +242,17 @@ where h1_parser_config: self.state.h1_parser_config.clone(), h1_max_headers: self.state.h1_max_headers, preserve_header_case: self.state.preserve_header_case, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: self.state.preserve_header_order, h09_responses: self.state.h09_responses, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut self.state.on_informational, }, ) { Poll::Ready(Ok(msg)) => msg, Poll::Ready(Err(e)) => return self.on_read_head_error(e), Poll::Pending => { - #[cfg(feature = "server")] + #[cfg(server)] if self.state.h1_header_read_timeout_running { if let Some(ref mut h1_header_read_timeout_fut) = self.state.h1_header_read_timeout_fut @@ -270,7 +270,7 @@ where } }; - #[cfg(feature = "server")] + #[cfg(server)] { self.state.h1_header_read_timeout_running = false; self.state.h1_header_read_timeout_fut = None; @@ -285,7 +285,7 @@ where self.state.h09_responses = false; // Drop any OnInformational callbacks, we're done there! - #[cfg(feature = "client")] + #[cfg(client)] { self.state.on_informational = None; } @@ -621,11 +621,11 @@ where Encode { head: &mut head, body, - #[cfg(feature = "server")] + #[cfg(server)] keep_alive: self.state.wants_keep_alive(), req_method: &mut self.state.method, title_case_headers: self.state.title_case_headers, - #[cfg(feature = "server")] + #[cfg(server)] date_header: self.state.date_header, }, buf, @@ -635,7 +635,7 @@ where debug_assert!(head.headers.is_empty()); self.state.cached_headers = Some(head.headers); - #[cfg(feature = "client")] + #[cfg(client)] { self.state.on_informational = head.extensions.remove::(); @@ -871,7 +871,7 @@ where self.state.close_write(); } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn disable_keep_alive(&mut self) { if self.state.is_idle() { trace!("disable_keep_alive; closing idle connection"); @@ -924,25 +924,25 @@ struct State { method: Option, h1_parser_config: ParserConfig, h1_max_headers: Option, - #[cfg(feature = "server")] + #[cfg(server)] h1_header_read_timeout: Option, - #[cfg(feature = "server")] + #[cfg(server)] h1_header_read_timeout_fut: Option>>, - #[cfg(feature = "server")] + #[cfg(server)] h1_header_read_timeout_running: bool, - #[cfg(feature = "server")] + #[cfg(server)] date_header: bool, - #[cfg(feature = "server")] + #[cfg(server)] timer: Time, preserve_header_case: bool, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: bool, title_case_headers: bool, h09_responses: bool, /// If set, called with each 1xx informational response received for /// the current request. MUST be unset after a non-1xx response is /// received. - #[cfg(feature = "client")] + #[cfg(client)] on_informational: Option, /// Set to true when the Dispatcher should poll read operations /// again. See the `maybe_notify` method for more. @@ -1123,7 +1123,7 @@ impl State { self.notify_read = true; } - #[cfg(feature = "server")] + #[cfg(server)] if self.h1_header_read_timeout.is_some() { // Next read will start and poll the header read timeout, // so we can close the connection if another header isn't @@ -1153,7 +1153,7 @@ impl State { #[cfg(test)] mod tests { - #[cfg(all(feature = "nightly", not(miri)))] + #[cfg(all(nightly, not(miri)))] #[bench] fn bench_read_head_short(b: &mut ::test::Bencher) { use super::*; diff --git a/src/proto/h1/decode.rs b/src/proto/h1/decode.rs index dd293e1228..d644fd72e2 100644 --- a/src/proto/h1/decode.rs +++ b/src/proto/h1/decode.rs @@ -1067,7 +1067,7 @@ mod tests { all_async_cases(content, content, Decoder::eof()).await; } - #[cfg(all(feature = "nightly", not(miri)))] + #[cfg(all(nightly, not(miri)))] #[bench] fn bench_decode_chunked_1kb(b: &mut test::Bencher) { let rt = new_runtime(); @@ -1096,7 +1096,7 @@ mod tests { }); } - #[cfg(all(feature = "nightly", not(miri)))] + #[cfg(all(nightly, not(miri)))] #[bench] fn bench_decode_length_1kb(b: &mut test::Bencher) { let rt = new_runtime(); @@ -1120,7 +1120,7 @@ mod tests { }); } - #[cfg(feature = "nightly")] + #[cfg(nightly)] fn new_runtime() -> tokio::runtime::Runtime { tokio::runtime::Builder::new_current_thread() .enable_all() diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index 4d921a3b83..0f07da4a20 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -13,7 +13,7 @@ use http::Request; use super::{Http1Transaction, Wants}; use crate::body::{Body, DecodedLength, Incoming as IncomingBody}; -#[cfg(feature = "client")] +#[cfg(client)] use crate::client::dispatch::TrySendError; use crate::common::task; use crate::proto::{BodyLength, Conn, Dispatched, MessageHead, RequestHead}; @@ -87,7 +87,7 @@ where } } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn disable_keep_alive(&mut self) { self.conn.disable_keep_alive(); diff --git a/src/proto/h1/encode.rs b/src/proto/h1/encode.rs index 2df0c396b7..c76767c0b2 100644 --- a/src/proto/h1/encode.rs +++ b/src/proto/h1/encode.rs @@ -44,7 +44,7 @@ enum Kind { /// /// This is mostly only used with HTTP/1.0 with a length. This kind requires /// the connection to be closed when the body is finished. - #[cfg(feature = "server")] + #[cfg(server)] CloseDelimited, } @@ -72,7 +72,7 @@ impl Encoder { Encoder::new(Kind::Length(len)) } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn close_delimited() -> Encoder { Encoder::new(Kind::CloseDelimited) } @@ -91,7 +91,7 @@ impl Encoder { matches!(self.kind, Kind::Length(0)) } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn set_last(mut self, is_last: bool) -> Self { self.is_last = is_last; self @@ -103,7 +103,7 @@ impl Encoder { pub(crate) fn is_close_delimited(&self) -> bool { match self.kind { - #[cfg(feature = "server")] + #[cfg(server)] Kind::CloseDelimited => true, _ => false, } @@ -119,7 +119,7 @@ impl Encoder { Kind::Chunked(_) => Ok(Some(EncodedBuf { kind: BufKind::ChunkedEnd(b"0\r\n\r\n"), })), - #[cfg(feature = "server")] + #[cfg(server)] Kind::CloseDelimited => Ok(None), Kind::Length(n) => Err(NotEof(n)), } @@ -151,7 +151,7 @@ impl Encoder { BufKind::Exact(msg) } } - #[cfg(feature = "server")] + #[cfg(server)] Kind::CloseDelimited => { trace!("close delimited write {}B", len); BufKind::Exact(msg) @@ -251,7 +251,7 @@ impl Encoder { } } } - #[cfg(feature = "server")] + #[cfg(server)] Kind::CloseDelimited => { trace!("close delimited write {}B", len); dst.buffer(msg); @@ -506,7 +506,7 @@ mod tests { assert!(encoder.end::<()>().unwrap().is_none()); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn eof() { let mut encoder = Encoder::close_delimited(); diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index d5afba683a..b05c88e699 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -74,7 +74,7 @@ where } } - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) fn set_flush_pipeline(&mut self, enabled: bool) { debug_assert!(!self.write_buf.has_remaining()); self.flush_pipeline = enabled; @@ -93,7 +93,7 @@ where self.write_buf.max_buf_size = max; } - #[cfg(feature = "client")] + #[cfg(client)] pub(crate) fn set_read_buf_exact_size(&mut self, sz: usize) { self.read_buf_strategy = ReadStrategy::Exact(sz); } @@ -117,7 +117,7 @@ where } #[cfg(test)] - #[cfg(feature = "nightly")] + #[cfg(nightly)] pub(super) fn read_buf_mut(&mut self) -> &mut BytesMut { &mut self.read_buf } @@ -185,10 +185,10 @@ where h1_parser_config: parse_ctx.h1_parser_config.clone(), h1_max_headers: parse_ctx.h1_max_headers, preserve_header_case: parse_ctx.preserve_header_case, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: parse_ctx.preserve_header_order, h09_responses: parse_ctx.h09_responses, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: parse_ctx.on_informational, }, )? { @@ -360,7 +360,7 @@ enum ReadStrategy { next: usize, max: usize, }, - #[cfg(feature = "client")] + #[cfg(client)] Exact(usize), } @@ -376,7 +376,7 @@ impl ReadStrategy { fn next(&self) -> usize { match *self { ReadStrategy::Adaptive { next, .. } => next, - #[cfg(feature = "client")] + #[cfg(client)] ReadStrategy::Exact(exact) => exact, } } @@ -384,7 +384,7 @@ impl ReadStrategy { fn max(&self) -> usize { match *self { ReadStrategy::Adaptive { max, .. } => max, - #[cfg(feature = "client")] + #[cfg(client)] ReadStrategy::Exact(exact) => exact, } } @@ -418,7 +418,7 @@ impl ReadStrategy { } } } - #[cfg(feature = "client")] + #[cfg(client)] ReadStrategy::Exact(_) => (), } } @@ -648,7 +648,7 @@ mod tests { use tokio_test::io::Builder as Mock; - // #[cfg(feature = "nightly")] + // #[cfg(nightly)] // use test::Bencher; /* @@ -707,10 +707,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }; assert!(buffered @@ -949,7 +949,7 @@ mod tests { assert_eq!(buffered.write_buf.queue.bufs_cnt(), 0); } - // #[cfg(feature = "nightly")] + // #[cfg(nightly)] // #[bench] // fn bench_write_buf_flatten_buffer_chunk(b: &mut Bencher) { // let s = "Hello, World!"; diff --git a/src/proto/h1/mod.rs b/src/proto/h1/mod.rs index a8f36f5fd9..e2a89d05a9 100644 --- a/src/proto/h1/mod.rs +++ b/src/proto/h1/mod.rs @@ -30,7 +30,7 @@ cfg_server! { pub(crate) trait Http1Transaction { type Incoming; type Outgoing: Default; - #[cfg(feature = "tracing")] + #[cfg(tracing)] const LOG: &'static str; fn parse(bytes: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult; fn encode(enc: Encode<'_, Self::Outgoing>, dst: &mut Vec) -> crate::Result; @@ -74,10 +74,10 @@ pub(crate) struct ParseContext<'a> { h1_parser_config: ParserConfig, h1_max_headers: Option, preserve_header_case: bool, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: bool, h09_responses: bool, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &'a mut Option, } @@ -85,11 +85,11 @@ pub(crate) struct ParseContext<'a> { pub(crate) struct Encode<'a, T> { head: &'a mut MessageHead, body: Option, - #[cfg(feature = "server")] + #[cfg(server)] keep_alive: bool, req_method: &'a mut Option, title_case_headers: bool, - #[cfg(feature = "server")] + #[cfg(server)] date_header: bool, } diff --git a/src/proto/h1/role.rs b/src/proto/h1/role.rs index 1674e26bc6..1ea9b0b03b 100644 --- a/src/proto/h1/role.rs +++ b/src/proto/h1/role.rs @@ -1,36 +1,36 @@ use std::mem::MaybeUninit; -#[cfg(feature = "client")] +#[cfg(client)] use std::fmt::{self, Write as _}; use bytes::Bytes; use bytes::BytesMut; -#[cfg(feature = "client")] +#[cfg(client)] use http::header::Entry; -#[cfg(feature = "server")] +#[cfg(server)] use http::header::ValueIter; use http::header::{self, HeaderMap, HeaderName, HeaderValue}; use http::{Method, StatusCode, Version}; use smallvec::{smallvec, smallvec_inline, SmallVec}; use crate::body::DecodedLength; -#[cfg(feature = "server")] +#[cfg(server)] use crate::common::date; use crate::error::Parse; use crate::ext::HeaderCaseMap; -#[cfg(feature = "ffi")] +#[cfg(ffi)] use crate::ext::OriginalHeaderOrder; use crate::headers; use crate::proto::h1::{ Encode, Encoder, Http1Transaction, ParseContext, ParseResult, ParsedMessage, }; -#[cfg(feature = "client")] +#[cfg(client)] use crate::proto::RequestHead; use crate::proto::{BodyLength, MessageHead, RequestLine}; pub(crate) const DEFAULT_MAX_HEADERS: usize = 100; const AVERAGE_HEADER_SIZE: usize = 30; // totally scientific -#[cfg(feature = "server")] +#[cfg(server)] const MAX_URI_LEN: usize = (u16::MAX - 1) as usize; macro_rules! header_name { @@ -121,17 +121,17 @@ where // There are 2 main roles, Client and Server. -#[cfg(feature = "client")] +#[cfg(client)] pub(crate) enum Client {} -#[cfg(feature = "server")] +#[cfg(server)] pub(crate) enum Server {} -#[cfg(feature = "server")] +#[cfg(server)] impl Http1Transaction for Server { type Incoming = RequestLine; type Outgoing = StatusCode; - #[cfg(feature = "tracing")] + #[cfg(tracing)] const LOG: &'static str = "{role=server}"; fn parse(buf: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult { @@ -235,7 +235,7 @@ impl Http1Transaction for Server { None }; - #[cfg(feature = "ffi")] + #[cfg(ffi)] let mut header_order = if ctx.preserve_header_order { Some(OriginalHeaderOrder::default()) } else { @@ -318,7 +318,7 @@ impl Http1Transaction for Server { header_case_map.append(&name, slice.slice(header.name.0..header.name.1)); } - #[cfg(feature = "ffi")] + #[cfg(ffi)] if let Some(ref mut header_order) = header_order { header_order.append(&name); } @@ -337,7 +337,7 @@ impl Http1Transaction for Server { extensions.insert(header_case_map); } - #[cfg(feature = "ffi")] + #[cfg(ffi)] if let Some(header_order) = header_order { extensions.insert(header_order); } @@ -489,7 +489,7 @@ impl Http1Transaction for Server { } } -#[cfg(feature = "server")] +#[cfg(server)] impl Server { fn can_have_body(method: &Option, status: StatusCode) -> bool { Server::can_chunked(method, status) @@ -973,7 +973,7 @@ impl Server { } } -#[cfg(feature = "server")] +#[cfg(server)] trait HeaderNameWriter { fn write_full_header_line( &mut self, @@ -990,11 +990,11 @@ trait HeaderNameWriter { fn write_header_name(&mut self, dst: &mut Vec, name: &HeaderName); } -#[cfg(feature = "client")] +#[cfg(client)] impl Http1Transaction for Client { type Incoming = StatusCode; type Outgoing = RequestLine; - #[cfg(feature = "tracing")] + #[cfg(tracing)] const LOG: &'static str = "{role=client}"; fn parse(buf: &mut BytesMut, ctx: ParseContext<'_>) -> ParseResult { @@ -1080,7 +1080,7 @@ impl Http1Transaction for Client { None }; - #[cfg(feature = "ffi")] + #[cfg(ffi)] let mut header_order = if ctx.preserve_header_order { Some(OriginalHeaderOrder::default()) } else { @@ -1109,7 +1109,7 @@ impl Http1Transaction for Client { header_case_map.append(&name, slice.slice(header.name.0..header.name.1)); } - #[cfg(feature = "ffi")] + #[cfg(ffi)] if let Some(ref mut header_order) = header_order { header_order.append(&name); } @@ -1123,7 +1123,7 @@ impl Http1Transaction for Client { extensions.insert(header_case_map); } - #[cfg(feature = "ffi")] + #[cfg(ffi)] if let Some(header_order) = header_order { extensions.insert(header_order); } @@ -1226,7 +1226,7 @@ impl Http1Transaction for Client { } } -#[cfg(feature = "client")] +#[cfg(client)] impl Client { /// Returns Some(length, wants_upgrade) if successful. /// @@ -1479,7 +1479,7 @@ impl Client { } } -#[cfg(feature = "client")] +#[cfg(client)] fn set_content_length(headers: &mut HeaderMap, len: u64) -> Encoder { // At this point, there should not be a valid Content-Length // header. However, since we'll be indexing in anyways, we can @@ -1579,7 +1579,7 @@ pub(crate) fn write_headers(headers: &HeaderMap, dst: &mut Vec) { } #[cold] -#[cfg(feature = "client")] +#[cfg(client)] fn write_headers_original_case( headers: &HeaderMap, orig_case: &HeaderCaseMap, @@ -1615,10 +1615,10 @@ fn write_headers_original_case( } } -#[cfg(feature = "client")] +#[cfg(client)] struct FastWrite<'a>(&'a mut Vec); -#[cfg(feature = "client")] +#[cfg(client)] impl fmt::Write for FastWrite<'_> { #[inline] fn write_str(&mut self, s: &str) -> fmt::Result { @@ -1643,7 +1643,7 @@ mod tests { use super::*; - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_parse_request() { let _ = pretty_env_logger::try_init(); @@ -1657,10 +1657,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ) @@ -1685,10 +1685,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }; let msg = Client::parse(&mut raw, ctx).unwrap().unwrap(); @@ -1699,7 +1699,7 @@ mod tests { assert_eq!(msg.head.headers["Content-Length"], "0"); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_parse_request_errors() { let mut raw = BytesMut::from("GET htt:p// HTTP/1.1\r\nHost: hyper.rs\r\n\r\n"); @@ -1709,10 +1709,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }; Server::parse(&mut raw, ctx).unwrap_err(); @@ -1730,10 +1730,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: true, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }; let msg = Client::parse(&mut raw, ctx).unwrap().unwrap(); @@ -1753,10 +1753,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }; Client::parse(&mut raw, ctx).unwrap_err(); @@ -1780,10 +1780,10 @@ mod tests { h1_parser_config, h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }; let msg = Client::parse(&mut raw, ctx).unwrap().unwrap(); @@ -1804,16 +1804,16 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }; Client::parse(&mut raw, ctx).unwrap_err(); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_parse_preserve_header_case_in_request() { let mut raw = @@ -1824,10 +1824,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: true, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }; let parsed_message = Server::parse(&mut raw, ctx).unwrap().unwrap(); @@ -1850,7 +1850,7 @@ mod tests { ); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_decoder_request() { fn parse(s: &str) -> ParsedMessage { @@ -1863,10 +1863,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ) @@ -1884,10 +1884,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ) @@ -2114,10 +2114,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, } ) @@ -2135,10 +2135,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ) @@ -2156,10 +2156,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ) @@ -2426,7 +2426,7 @@ mod tests { ); } - #[cfg(feature = "client")] + #[cfg(client)] #[test] fn test_client_obs_fold_line() { fn unfold(src: &str) -> String { @@ -2461,11 +2461,11 @@ mod tests { Encode { head: &mut head, body: Some(BodyLength::Known(10)), - #[cfg(feature = "server")] + #[cfg(server)] keep_alive: true, req_method: &mut None, title_case_headers: true, - #[cfg(feature = "server")] + #[cfg(server)] date_header: true, }, &mut vec, @@ -2495,11 +2495,11 @@ mod tests { Encode { head: &mut head, body: Some(BodyLength::Known(10)), - #[cfg(feature = "server")] + #[cfg(server)] keep_alive: true, req_method: &mut None, title_case_headers: false, - #[cfg(feature = "server")] + #[cfg(server)] date_header: true, }, &mut vec, @@ -2532,11 +2532,11 @@ mod tests { Encode { head: &mut head, body: Some(BodyLength::Known(10)), - #[cfg(feature = "server")] + #[cfg(server)] keep_alive: true, req_method: &mut None, title_case_headers: true, - #[cfg(feature = "server")] + #[cfg(server)] date_header: true, }, &mut vec, @@ -2550,7 +2550,7 @@ mod tests { ); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_server_encode_connect_method() { let mut head = MessageHead::default(); @@ -2572,7 +2572,7 @@ mod tests { assert!(encoder.is_last()); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_server_response_encode_title_case() { use crate::proto::BodyLength; @@ -2606,7 +2606,7 @@ mod tests { assert_eq!(&vec[..expected_response.len()], &expected_response[..]); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_server_response_encode_orig_case() { use crate::proto::BodyLength; @@ -2642,7 +2642,7 @@ mod tests { assert_eq!(&vec[..expected_response.len()], &expected_response[..]); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_server_response_encode_orig_and_title_case() { use crate::proto::BodyLength; @@ -2679,7 +2679,7 @@ mod tests { assert_eq!(&vec[..expected_response.len()], &expected_response[..]); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn test_disabled_date_header() { use crate::proto::BodyLength; @@ -2726,10 +2726,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ) @@ -2739,7 +2739,7 @@ mod tests { assert_eq!(parsed.head.headers["server"], "hello\tworld"); } - #[cfg(feature = "server")] + #[cfg(server)] #[test] fn parse_too_large_headers() { fn gen_req_with_headers(num: usize) -> String { @@ -2770,10 +2770,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: max_headers, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ); @@ -2794,10 +2794,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: max_headers, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ); @@ -2925,10 +2925,10 @@ mod tests { assert_eq!(dst, b"X-Empty: a\r\nX-EMPTY: b\r\n"); } - #[cfg(feature = "nightly")] + #[cfg(nightly)] use test::Bencher; - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn bench_parse_incoming(b: &mut Bencher) { let mut raw = BytesMut::from( @@ -2963,10 +2963,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ) @@ -2990,7 +2990,7 @@ mod tests { } } - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn bench_parse_short(b: &mut Bencher) { let s = &b"GET / HTTP/1.1\r\nHost: localhost:8080\r\n\r\n"[..]; @@ -3008,10 +3008,10 @@ mod tests { h1_parser_config: Default::default(), h1_max_headers: None, preserve_header_case: false, - #[cfg(feature = "ffi")] + #[cfg(ffi)] preserve_header_order: false, h09_responses: false, - #[cfg(feature = "client")] + #[cfg(client)] on_informational: &mut None, }, ) @@ -3031,7 +3031,7 @@ mod tests { } } - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn bench_server_encode_headers_preset(b: &mut Bencher) { use crate::proto::BodyLength; @@ -3065,7 +3065,7 @@ mod tests { }) } - #[cfg(feature = "nightly")] + #[cfg(nightly)] #[bench] fn bench_server_encode_no_headers(b: &mut Bencher) { use crate::proto::BodyLength; diff --git a/src/proto/h2/ping.rs b/src/proto/h2/ping.rs index 749cf1b7c0..d831cd179a 100644 --- a/src/proto/h2/ping.rs +++ b/src/proto/h2/ping.rs @@ -232,7 +232,7 @@ impl Recorder { /// If the incoming stream is already closed, convert self into /// a disabled reporter. - #[cfg(feature = "client")] + #[cfg(client)] pub(super) fn for_stream(self, stream: &h2::RecvStream) -> Self { if stream.is_end_stream() { disabled() diff --git a/src/proto/mod.rs b/src/proto/mod.rs index fcdf2b97c0..2ae892ce3d 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -1,23 +1,23 @@ //! Pieces pertaining to the HTTP message protocol. cfg_feature! { - #![feature = "http1"] + #![http1] pub(crate) mod h1; pub(crate) use self::h1::Conn; - #[cfg(feature = "client")] + #[cfg(client)] pub(crate) use self::h1::dispatch; - #[cfg(feature = "server")] + #[cfg(server)] pub(crate) use self::h1::ServerTransaction; } -#[cfg(feature = "http2")] +#[cfg(http2)] pub(crate) mod h2; /// An Incoming Message head. Includes request/status line, and headers. -#[cfg(feature = "http1")] +#[cfg(http1)] #[derive(Debug, Default)] pub(crate) struct MessageHead { /// HTTP version of the message. @@ -31,19 +31,19 @@ pub(crate) struct MessageHead { } /// An incoming request message. -#[cfg(feature = "http1")] +#[cfg(http1)] pub(crate) type RequestHead = MessageHead; #[derive(Debug, Default, PartialEq)] -#[cfg(feature = "http1")] +#[cfg(http1)] pub(crate) struct RequestLine(pub(crate) http::Method, pub(crate) http::Uri); /// An incoming response message. -#[cfg(all(feature = "http1", feature = "client"))] +#[cfg(http_client)] pub(crate) type ResponseHead = MessageHead; #[derive(Debug)] -#[cfg(feature = "http1")] +#[cfg(http1)] pub(crate) enum BodyLength { /// Content-Length Known(u64), @@ -56,11 +56,11 @@ pub(crate) enum Dispatched { /// Dispatcher completely shutdown connection. Shutdown, /// Dispatcher has pending upgrade, and so did not shutdown. - #[cfg(feature = "http1")] + #[cfg(http1)] Upgrade(crate::upgrade::Pending), } -#[cfg(all(feature = "client", feature = "http1"))] +#[cfg(http1_client)] impl MessageHead { fn into_response(self, body: B) -> http::Response { let mut res = http::Response::new(body); diff --git a/src/rt/bounds.rs b/src/rt/bounds.rs index aa3075e079..e243eae58f 100644 --- a/src/rt/bounds.rs +++ b/src/rt/bounds.rs @@ -3,14 +3,14 @@ //! Traits in this module ease setting bounds and usually automatically //! implemented by implementing another trait. -#[cfg(all(feature = "server", feature = "http2"))] +#[cfg(http2_server)] pub use self::h2::Http2ServerConnExec; -#[cfg(all(feature = "client", feature = "http2"))] +#[cfg(http2_client)] pub use self::h2_client::Http2ClientConnExec; -#[cfg(all(feature = "client", feature = "http2"))] -#[cfg_attr(docsrs, doc(cfg(all(feature = "client", feature = "http2"))))] +#[cfg(http2_client)] +#[cfg_attr(docsrs, doc(cfg(http2_client)))] mod h2_client { use std::{error::Error, future::Future}; @@ -63,8 +63,8 @@ mod h2_client { } } -#[cfg(all(feature = "server", feature = "http2"))] -#[cfg_attr(docsrs, doc(cfg(all(feature = "server", feature = "http2"))))] +#[cfg(http2_server)] +#[cfg_attr(docsrs, doc(cfg(http2_server)))] mod h2 { use crate::{proto::h2::server::H2Stream, rt::Executor}; use http_body::Body; diff --git a/src/rt/io.rs b/src/rt/io.rs index ed4af0929f..9a80525e9c 100644 --- a/src/rt/io.rs +++ b/src/rt/io.rs @@ -177,25 +177,25 @@ impl<'data> ReadBuf<'data> { } #[inline] - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] pub(crate) unsafe fn set_init(&mut self, n: usize) { self.init = self.init.max(n); } #[inline] - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] pub(crate) unsafe fn set_filled(&mut self, n: usize) { self.filled = self.filled.max(n); } #[inline] - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] pub(crate) fn len(&self) -> usize { self.filled } #[inline] - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(any(http2_client, http2_server))] pub(crate) fn init_len(&self) -> usize { self.init } diff --git a/src/server/conn/http2.rs b/src/server/conn/http2.rs index e0d61c13a6..2b15395b68 100644 --- a/src/server/conn/http2.rs +++ b/src/server/conn/http2.rs @@ -139,8 +139,8 @@ impl Builder { /// This is not advised, as it can potentially expose servers to DOS vulnerabilities. /// /// See for more information. - #[cfg(feature = "http2")] - #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + #[cfg(http2)] + #[cfg_attr(docsrs, doc(cfg(http2)))] pub fn max_local_error_reset_streams(&mut self, max: impl Into>) -> &mut Self { self.h2_builder.max_local_error_reset_streams = max.into(); self diff --git a/src/server/conn/mod.rs b/src/server/conn/mod.rs index 54b309e88e..28ede55034 100644 --- a/src/server/conn/mod.rs +++ b/src/server/conn/mod.rs @@ -14,7 +14,7 @@ //! module, allowing you to set configuration for both. The builder will then check //! the version of the incoming connection and serve it accordingly. -#[cfg(feature = "http1")] +#[cfg(http1)] pub mod http1; -#[cfg(feature = "http2")] +#[cfg(http2)] pub mod http2; diff --git a/src/trace.rs b/src/trace.rs index 88f9a243a0..373625ae96 100644 --- a/src/trace.rs +++ b/src/trace.rs @@ -2,7 +2,7 @@ // even if they are not used at the present time. #![allow(unused_macros)] -#[cfg(all(not(hyper_unstable_tracing), feature = "tracing"))] +#[cfg(all(not(hyper_unstable_tracing), tracing))] compile_error!( "\ The `tracing` feature is unstable, and requires the \ @@ -12,7 +12,7 @@ compile_error!( macro_rules! debug { ($($arg:tt)+) => { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { tracing::debug!($($arg)+); } @@ -22,7 +22,7 @@ macro_rules! debug { macro_rules! debug_span { ($($arg:tt)*) => { { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { let _span = tracing::debug_span!($($arg)+); _span.entered() @@ -33,7 +33,7 @@ macro_rules! debug_span { macro_rules! error { ($($arg:tt)*) => { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { tracing::error!($($arg)+); } @@ -43,7 +43,7 @@ macro_rules! error { macro_rules! error_span { ($($arg:tt)*) => { { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { let _span = tracing::error_span!($($arg)+); _span.entered() @@ -54,7 +54,7 @@ macro_rules! error_span { macro_rules! info { ($($arg:tt)*) => { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { tracing::info!($($arg)+); } @@ -64,7 +64,7 @@ macro_rules! info { macro_rules! info_span { ($($arg:tt)*) => { { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { let _span = tracing::info_span!($($arg)+); _span.entered() @@ -75,7 +75,7 @@ macro_rules! info_span { macro_rules! trace { ($($arg:tt)*) => { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { tracing::trace!($($arg)+); } @@ -85,7 +85,7 @@ macro_rules! trace { macro_rules! trace_span { ($($arg:tt)*) => { { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { let _span = tracing::trace_span!($($arg)+); _span.entered() @@ -97,7 +97,7 @@ macro_rules! trace_span { macro_rules! span { ($($arg:tt)*) => { { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { let _span = tracing::span!($($arg)+); _span.entered() @@ -108,7 +108,7 @@ macro_rules! span { macro_rules! warn { ($($arg:tt)*) => { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { tracing::warn!($($arg)+); } @@ -118,7 +118,7 @@ macro_rules! warn { macro_rules! warn_span { ($($arg:tt)*) => { { - #[cfg(feature = "tracing")] + #[cfg(tracing)] { let _span = tracing::warn_span!($($arg)+); _span.entered() diff --git a/src/upgrade.rs b/src/upgrade.rs index 9d23a29081..d102507377 100644 --- a/src/upgrade.rs +++ b/src/upgrade.rs @@ -106,18 +106,12 @@ pub fn on(msg: T) -> OnUpgrade { msg.on_upgrade() } -#[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2"), -))] +#[cfg(any(http_client, http_server))] pub(super) struct Pending { tx: oneshot::Sender>, } -#[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2"), -))] +#[cfg(any(http_client, http_server))] pub(super) fn pending() -> (Pending, OnUpgrade) { let (tx, rx) = oneshot::channel(); ( @@ -131,10 +125,7 @@ pub(super) fn pending() -> (Pending, OnUpgrade) { // ===== impl Upgraded ===== impl Upgraded { - #[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") - ))] + #[cfg(any(http_client, http_server))] pub(super) fn new(io: T, read_buf: Bytes) -> Self where T: Read + Write + Unpin + Send + 'static, @@ -215,7 +206,7 @@ impl OnUpgrade { OnUpgrade { rx: None } } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] + #[cfg(any(http1_client, http1_server))] pub(super) fn is_none(&self) -> bool { self.rx.is_none() } @@ -248,21 +239,18 @@ impl fmt::Debug for OnUpgrade { // ===== impl Pending ===== -#[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2") -))] +#[cfg(any(http_client, http_server))] impl Pending { pub(super) fn fulfill(self, upgraded: Upgraded) { trace!("pending upgrade fulfill"); let _ = self.tx.send(Ok(upgraded)); } - #[cfg(feature = "http1")] + #[cfg(http1)] /// Don't fulfill the pending Upgrade, but instead signal that /// upgrades are handled manually. pub(super) fn manual(self) { - #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(any(http1, http2))] trace!("pending upgrade handled manually"); let _ = self.tx.send(Err(crate::Error::new_user_manual_upgrade())); } @@ -354,10 +342,7 @@ mod sealed { } } -#[cfg(all( - any(feature = "client", feature = "server"), - any(feature = "http1", feature = "http2"), -))] +#[cfg(any(http_client, http_server))] #[cfg(test)] mod tests { use super::*; diff --git a/tests/server.rs b/tests/server.rs index 2ba6f92ca3..b497f9174f 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -1377,7 +1377,7 @@ async fn nonempty_parse_eof_returns_error() { .expect_err("partial parse eof is error"); } -#[cfg(feature = "http1")] +#[cfg(http1)] #[tokio::test] async fn http1_allow_half_close() { let (listener, addr) = setup_tcp_listener(); @@ -1411,7 +1411,7 @@ async fn http1_allow_half_close() { t1.join().expect("client thread"); } -#[cfg(feature = "http1")] +#[cfg(http1)] #[tokio::test] async fn disconnect_after_reading_request_before_responding() { let (listener, addr) = setup_tcp_listener(); @@ -2324,7 +2324,7 @@ async fn illegal_request_length_returns_400_response() { .expect_err("illegal Content-Length should error"); } -#[cfg(feature = "http1")] +#[cfg(http1)] #[test] #[should_panic] fn max_buf_size_panic_too_small() { @@ -2332,14 +2332,14 @@ fn max_buf_size_panic_too_small() { http1::Builder::new().max_buf_size(MAX); } -#[cfg(feature = "http1")] +#[cfg(http1)] #[test] fn max_buf_size_no_panic() { const MAX: usize = 8193; http1::Builder::new().max_buf_size(MAX); } -#[cfg(feature = "http1")] +#[cfg(http1)] #[tokio::test] async fn max_buf_size() { let (listener, addr) = setup_tcp_listener(); @@ -2366,7 +2366,7 @@ async fn max_buf_size() { .expect_err("should TooLarge error"); } -#[cfg(feature = "http1")] +#[cfg(http1)] #[tokio::test] async fn graceful_shutdown_before_first_request_no_block() { let (listener, addr) = setup_tcp_listener();