refactor(lib): Use cfg(all(...)) instead of multiple cfg attributes
This commit is contained in:
committed by
Sean McArthur
parent
2c8121f173
commit
9dff00425d
@@ -16,8 +16,7 @@ use super::DecodedLength;
|
|||||||
#[cfg(feature = "stream")]
|
#[cfg(feature = "stream")]
|
||||||
use crate::common::sync_wrapper::SyncWrapper;
|
use crate::common::sync_wrapper::SyncWrapper;
|
||||||
use crate::common::Future;
|
use crate::common::Future;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
use crate::common::Never;
|
use crate::common::Never;
|
||||||
use crate::common::{task, watch, Pin, Poll};
|
use crate::common::{task, watch, Pin, Poll};
|
||||||
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
|
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
|
||||||
@@ -74,8 +73,7 @@ struct Extra {
|
|||||||
delayed_eof: Option<DelayEof>,
|
delayed_eof: Option<DelayEof>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
type DelayEofUntil = oneshot::Receiver<Never>;
|
type DelayEofUntil = oneshot::Receiver<Never>;
|
||||||
|
|
||||||
enum DelayEof {
|
enum DelayEof {
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ use std::fmt;
|
|||||||
#[cfg(feature = "http2")]
|
#[cfg(feature = "http2")]
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(all(feature = "runtime", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@@ -63,7 +62,10 @@ use tower_service::Service;
|
|||||||
|
|
||||||
use super::dispatch;
|
use super::dispatch;
|
||||||
use crate::body::HttpBody;
|
use crate::body::HttpBody;
|
||||||
use crate::common::{task, exec::{BoxSendFuture, Exec}, Future, Pin, Poll};
|
use crate::common::{
|
||||||
|
exec::{BoxSendFuture, Exec},
|
||||||
|
task, Future, Pin, Poll,
|
||||||
|
};
|
||||||
use crate::proto;
|
use crate::proto;
|
||||||
use crate::rt::Executor;
|
use crate::rt::Executor;
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(feature = "http1")]
|
||||||
|
|||||||
@@ -52,8 +52,7 @@
|
|||||||
pub use self::connect::HttpConnector;
|
pub use self::connect::HttpConnector;
|
||||||
|
|
||||||
pub mod connect;
|
pub mod connect;
|
||||||
#[cfg(test)]
|
#[cfg(all(test, feature = "runtime"))]
|
||||||
#[cfg(feature = "runtime")]
|
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
cfg_feature! {
|
cfg_feature! {
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
use crate::body::{Body, HttpBody};
|
use crate::body::{Body, HttpBody};
|
||||||
#[cfg(feature = "http2")]
|
#[cfg(all(feature = "http2", feature = "server"))]
|
||||||
#[cfg(feature = "server")]
|
|
||||||
use crate::proto::h2::server::H2Stream;
|
use crate::proto::h2::server::H2Stream;
|
||||||
use crate::rt::Executor;
|
use crate::rt::Executor;
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
|
|||||||
@@ -8,17 +8,14 @@ macro_rules! ready {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) mod buf;
|
pub(crate) mod buf;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
|
||||||
#[cfg(feature = "server")]
|
|
||||||
pub(crate) mod date;
|
pub(crate) mod date;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
|
||||||
#[cfg(feature = "server")]
|
|
||||||
pub(crate) mod drain;
|
pub(crate) mod drain;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||||
pub(crate) mod exec;
|
pub(crate) mod exec;
|
||||||
pub(crate) mod io;
|
pub(crate) mod io;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
mod lazy;
|
mod lazy;
|
||||||
mod never;
|
mod never;
|
||||||
#[cfg(feature = "stream")]
|
#[cfg(feature = "stream")]
|
||||||
@@ -26,8 +23,7 @@ pub(crate) mod sync_wrapper;
|
|||||||
pub(crate) mod task;
|
pub(crate) mod task;
|
||||||
pub(crate) mod watch;
|
pub(crate) mod watch;
|
||||||
|
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
pub(crate) use self::lazy::{lazy, Started as Lazy};
|
pub(crate) use self::lazy::{lazy, Started as Lazy};
|
||||||
#[cfg(any(
|
#[cfg(any(
|
||||||
feature = "client",
|
feature = "client",
|
||||||
|
|||||||
@@ -2,10 +2,9 @@
|
|||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use http::header::CONTENT_LENGTH;
|
use http::header::CONTENT_LENGTH;
|
||||||
use http::header::{HeaderValue, ValueIter};
|
use http::header::{HeaderValue, ValueIter};
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
#[cfg(feature = "client")]
|
|
||||||
use http::Method;
|
|
||||||
use http::HeaderMap;
|
use http::HeaderMap;
|
||||||
|
#[cfg(all(feature = "http2", feature = "client"))]
|
||||||
|
use http::Method;
|
||||||
|
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(feature = "http1")]
|
||||||
pub(super) fn connection_keep_alive(value: &HeaderValue) -> bool {
|
pub(super) fn connection_keep_alive(value: &HeaderValue) -> bool {
|
||||||
@@ -29,8 +28,7 @@ fn connection_has(value: &HeaderValue, needle: &str) -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "server"))]
|
||||||
#[cfg(feature = "server")]
|
|
||||||
pub(super) fn content_length_parse(value: &HeaderValue) -> Option<u64> {
|
pub(super) fn content_length_parse(value: &HeaderValue) -> Option<u64> {
|
||||||
value.to_str().ok().and_then(|s| s.parse().ok())
|
value.to_str().ok().and_then(|s| s.parse().ok())
|
||||||
}
|
}
|
||||||
@@ -66,8 +64,7 @@ pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "http2")]
|
#[cfg(all(feature = "http2", feature = "client"))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
pub(super) fn method_has_defined_payload_semantics(method: &Method) -> bool {
|
pub(super) fn method_has_defined_payload_semantics(method: &Method) -> bool {
|
||||||
match *method {
|
match *method {
|
||||||
Method::GET | Method::HEAD | Method::DELETE | Method::CONNECT => false,
|
Method::GET | Method::HEAD | Method::DELETE | Method::CONNECT => false,
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ pub(crate) type RequestHead = MessageHead<RequestLine>;
|
|||||||
pub(crate) struct RequestLine(pub(crate) http::Method, pub(crate) http::Uri);
|
pub(crate) struct RequestLine(pub(crate) http::Method, pub(crate) http::Uri);
|
||||||
|
|
||||||
/// An incoming response message.
|
/// An incoming response message.
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "client"))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
pub(crate) type ResponseHead = MessageHead<http::StatusCode>;
|
pub(crate) type ResponseHead = MessageHead<http::StatusCode>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ use std::fmt;
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
#[cfg(feature = "tcp")]
|
#[cfg(feature = "tcp")]
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(all(feature = "runtime", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@@ -63,8 +62,7 @@ use crate::common::exec::{ConnStreamExec, Exec, NewSvcExec};
|
|||||||
#[cfg(feature = "http2")]
|
#[cfg(feature = "http2")]
|
||||||
use crate::common::io::Rewind;
|
use crate::common::io::Rewind;
|
||||||
use crate::common::{task, Future, Pin, Poll, Unpin};
|
use crate::common::{task, Future, Pin, Poll, Unpin};
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
use crate::error::{Kind, Parse};
|
use crate::error::{Kind, Parse};
|
||||||
use crate::proto;
|
use crate::proto;
|
||||||
use crate::service::{HttpService, MakeServiceRef};
|
use crate::service::{HttpService, MakeServiceRef};
|
||||||
@@ -107,8 +105,7 @@ enum ConnectionMode {
|
|||||||
#[cfg(feature = "http2")]
|
#[cfg(feature = "http2")]
|
||||||
H2Only,
|
H2Only,
|
||||||
/// Use HTTP/1 and try to upgrade to h2 when a parse error occurs.
|
/// Use HTTP/1 and try to upgrade to h2 when a parse error occurs.
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
Fallback,
|
Fallback,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,8 +157,7 @@ where
|
|||||||
S: HttpService<Body>,
|
S: HttpService<Body>,
|
||||||
{
|
{
|
||||||
pub(super) conn: Option<ProtoServer<T, S::ResBody, S, E>>,
|
pub(super) conn: Option<ProtoServer<T, S::ResBody, S, E>>,
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
fallback: Fallback<E>,
|
fallback: Fallback<E>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,16 +182,14 @@ where
|
|||||||
H2(#[pin] proto::h2::Server<Rewind<T>, S, B, E>),
|
H2(#[pin] proto::h2::Server<Rewind<T>, S, B, E>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
enum Fallback<E> {
|
enum Fallback<E> {
|
||||||
ToHttp2(proto::h2::server::Config, E),
|
ToHttp2(proto::h2::server::Config, E),
|
||||||
Http1Only,
|
Http1Only,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
impl<E> Fallback<E> {
|
impl<E> Fallback<E> {
|
||||||
fn to_h2(&self) -> bool {
|
fn to_h2(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
@@ -205,8 +199,7 @@ impl<E> Fallback<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
impl<E> Unpin for Fallback<E> {}
|
impl<E> Unpin for Fallback<E> {}
|
||||||
|
|
||||||
/// Deconstructed parts of a `Connection`.
|
/// Deconstructed parts of a `Connection`.
|
||||||
@@ -701,8 +694,7 @@ where
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "http1")]
|
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||||
#[cfg(feature = "http2")]
|
|
||||||
fn upgrade_h2(&mut self) {
|
fn upgrade_h2(&mut self) {
|
||||||
trace!("Trying to upgrade connection to h2");
|
trace!("Trying to upgrade connection to h2");
|
||||||
let conn = self.conn.take();
|
let conn = self.conn.take();
|
||||||
|
|||||||
@@ -39,20 +39,16 @@ pub use tower_service::Service;
|
|||||||
|
|
||||||
mod http;
|
mod http;
|
||||||
mod make;
|
mod make;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
mod oneshot;
|
mod oneshot;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
pub(super) use self::http::HttpService;
|
pub(super) use self::http::HttpService;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
pub(super) use self::make::MakeConnection;
|
pub(super) use self::make::MakeConnection;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "server"))]
|
||||||
#[cfg(feature = "server")]
|
|
||||||
pub(super) use self::make::MakeServiceRef;
|
pub(super) use self::make::MakeServiceRef;
|
||||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
|
||||||
#[cfg(feature = "client")]
|
|
||||||
pub(super) use self::oneshot::{oneshot, Oneshot};
|
pub(super) use self::oneshot::{oneshot, Oneshot};
|
||||||
|
|
||||||
pub use self::make::make_service_fn;
|
pub use self::make::make_service_fn;
|
||||||
|
|||||||
Reference in New Issue
Block a user