diff --git a/Cargo.toml b/Cargo.toml index 0c4b8de00a..c055d3fdf0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,11 +74,12 @@ pnet = "0.25.0" default = [ "runtime", "stream", - + "client", "http1", "http2", ] full = [ + "client", "http1", "http2", "stream", @@ -99,6 +100,8 @@ tcp = [ http1 = [] http2 = ["h2"] +client = [] + # `impl Stream` for things stream = [] diff --git a/src/body/body.rs b/src/body/body.rs index 5583ba9839..4cc5ab1644 100644 --- a/src/body/body.rs +++ b/src/body/body.rs @@ -6,6 +6,7 @@ use std::fmt; use bytes::Bytes; use futures_channel::mpsc; #[cfg(any(feature = "http1", feature = "http2"))] +#[cfg(feature = "client")] use futures_channel::oneshot; use futures_core::Stream; // for mpsc::Receiver #[cfg(feature = "stream")] @@ -18,6 +19,7 @@ use super::DecodedLength; use crate::common::sync_wrapper::SyncWrapper; use crate::common::{task, watch, Pin, Poll}; #[cfg(any(feature = "http1", feature = "http2"))] +#[cfg(feature = "client")] use crate::common::{Future, Never}; #[cfg(feature = "http2")] use crate::proto::h2::ping; @@ -72,16 +74,19 @@ struct Extra { } #[cfg(any(feature = "http1", feature = "http2"))] +#[cfg(feature = "client")] type DelayEofUntil = oneshot::Receiver; enum DelayEof { /// Initial state, stream hasn't seen EOF yet. #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] NotEof(DelayEofUntil), /// Transitions to this state once we've seen `poll` try to /// return EOF (`None`). This future is then polled, and /// when it completes, the Body finally returns EOF (`None`). #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] Eof(DelayEofUntil), } @@ -219,6 +224,7 @@ impl Body { } #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] pub(crate) fn delayed_eof(&mut self, fut: DelayEofUntil) { self.extra_mut().delayed_eof = Some(DelayEof::NotEof(fut)); } @@ -242,6 +248,7 @@ impl Body { fn poll_eof(&mut self, cx: &mut task::Context<'_>) -> Poll>> { match self.take_delayed_eof() { #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] Some(DelayEof::NotEof(mut delay)) => match self.poll_inner(cx) { ok @ Poll::Ready(Some(Ok(..))) | ok @ Poll::Pending => { self.extra_mut().delayed_eof = Some(DelayEof::NotEof(delay)); @@ -258,6 +265,7 @@ impl Body { Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))), }, #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] Some(DelayEof::Eof(mut delay)) => match Pin::new(&mut delay).poll(cx) { Poll::Ready(Ok(never)) => match never {}, Poll::Pending => { @@ -266,7 +274,10 @@ impl Body { } Poll::Ready(Err(_done)) => Poll::Ready(None), }, - #[cfg(not(any(feature = "http1", feature = "http2")))] + #[cfg(any( + not(any(feature = "http1", feature = "http2")), + not(feature = "client") + ))] Some(delay_eof) => match delay_eof {}, None => self.poll_inner(cx), } diff --git a/src/cfg.rs b/src/cfg.rs index 86d211d067..d051b21849 100644 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -1,37 +1,50 @@ -macro_rules! cfg_any_http { - ($($item:item)*) => { +macro_rules! cfg_feature { + ( + #![$meta:meta] + $($item:item)* + ) => { $( - #[cfg(any( - feature = "http1", - feature = "http2", - ))] - #[cfg_attr(docsrs, doc(cfg(any( - feature = "http1", - feature = "http2", - ))))] + #[cfg($meta)] + #[cfg_attr(docsrs, doc(cfg($meta)))] $item )* } } +macro_rules! cfg_any_http { + ($($item:item)*) => { + cfg_feature! { + #![any(feature = "http1", feature = "http2")] + $($item)* + } + } +} + cfg_any_http! { macro_rules! cfg_http1 { ($($item:item)*) => { - $( - #[cfg(feature = "http1")] - #[cfg_attr(docsrs, doc(cfg(feature = "http1")))] - $item - )* + cfg_feature! { + #![feature = "http1"] + $($item)* + } } } macro_rules! cfg_http2 { ($($item:item)*) => { - $( - #[cfg(feature = "http2")] - #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] - $item - )* + cfg_feature! { + #![feature = "http2"] + $($item)* + } + } + } + + macro_rules! cfg_client { + ($($item:item)*) => { + cfg_feature! { + #![feature = "client"] + $($item)* + } } } } diff --git a/src/client/conn.rs b/src/client/conn.rs index 1420781e6d..c519cc30c7 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -25,7 +25,7 @@ use tower_service::Service; use super::dispatch; use crate::body::HttpBody; -use crate::common::{task, BoxSendFuture, Exec, Future, Pin, Poll}; +use crate::common::{task, exec::{BoxSendFuture, Exec}, Future, Pin, Poll}; use crate::proto; use crate::rt::Executor; #[cfg(feature = "http1")] diff --git a/src/client/mod.rs b/src/client/mod.rs index a227b44683..b2064d20ab 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -62,7 +62,7 @@ use http::{Method, Request, Response, Uri, Version}; use self::connect::{sealed::Connect, Alpn, Connected, Connection}; use self::pool::{Key as PoolKey, Pool, Poolable, Pooled, Reservation}; use crate::body::{Body, HttpBody}; -use crate::common::{lazy as hyper_lazy, task, BoxSendFuture, Future, Lazy, Pin, Poll}; +use crate::common::{lazy as hyper_lazy, task, exec::BoxSendFuture, Future, Lazy, Pin, Poll}; use crate::rt::Executor; #[cfg(feature = "tcp")] diff --git a/src/client/pool.rs b/src/client/pool.rs index 67a63f69d1..777b4789b4 100644 --- a/src/client/pool.rs +++ b/src/client/pool.rs @@ -11,7 +11,7 @@ use futures_channel::oneshot; use tokio::time::{Duration, Instant, Interval}; use super::Ver; -use crate::common::{task, Exec, Future, Pin, Poll, Unpin}; +use crate::common::{task, exec::Exec, Future, Pin, Poll, Unpin}; // FIXME: allow() required due to `impl Trait` leaking types to this lint #[allow(missing_debug_implementations)] @@ -777,7 +777,7 @@ mod tests { use std::time::Duration; use super::{Connecting, Key, Pool, Poolable, Reservation, WeakOpt}; - use crate::common::{task, Exec, Future, Pin}; + use crate::common::{task, exec::Exec, Future, Pin}; /// Test unique reservations. #[derive(Debug, PartialEq, Eq)] diff --git a/src/common/mod.rs b/src/common/mod.rs index e1ac726185..fc7272d44a 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -16,6 +16,7 @@ pub(crate) mod drain; pub(crate) mod exec; pub(crate) mod io; #[cfg(any(feature = "http1", feature = "http2"))] +#[cfg(feature = "client")] mod lazy; mod never; #[cfg(feature = "stream")] @@ -23,9 +24,10 @@ pub(crate) mod sync_wrapper; pub(crate) mod task; pub(crate) mod watch; +//#[cfg(any(feature = "http1", feature = "http2"))] +//pub(crate) use self::exec::{BoxSendFuture, Exec}; #[cfg(any(feature = "http1", feature = "http2"))] -pub(crate) use self::exec::{BoxSendFuture, Exec}; -#[cfg(any(feature = "http1", feature = "http2"))] +#[cfg(feature = "client")] pub(crate) use self::lazy::{lazy, Started as Lazy}; pub use self::never::Never; pub(crate) use self::task::Poll; diff --git a/src/error.rs b/src/error.rs index 30704eee3f..aa516e4963 100644 --- a/src/error.rs +++ b/src/error.rs @@ -88,15 +88,18 @@ pub(crate) enum User { UnexpectedHeader, /// User tried to create a Request with bad version. #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] UnsupportedVersion, /// User tried to create a CONNECT Request with the Client. #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] UnsupportedRequestMethod, /// User tried to respond with a 1xx (not 101) response code. #[cfg(feature = "http1")] UnsupportedStatusCode, /// User tried to send a Request with Client with non-absolute URI. #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] AbsoluteUriRequired, /// User tried polling for an upgrade that doesn't exist. @@ -241,6 +244,7 @@ impl Error { } #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] pub(crate) fn new_connect>(cause: E) -> Error { Error::new(Kind::Connect).with(cause) } @@ -273,11 +277,13 @@ impl Error { } #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] pub(crate) fn new_user_unsupported_version() -> Error { Error::new_user(User::UnsupportedVersion) } #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] pub(crate) fn new_user_unsupported_request_method() -> Error { Error::new_user(User::UnsupportedRequestMethod) } @@ -288,6 +294,7 @@ impl Error { } #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] pub(crate) fn new_user_absolute_uri_required() -> Error { Error::new_user(User::AbsoluteUriRequired) } @@ -371,14 +378,17 @@ impl Error { #[cfg(feature = "http1")] Kind::User(User::UnexpectedHeader) => "user sent unexpected header", #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] Kind::User(User::UnsupportedVersion) => "request has unsupported HTTP version", #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] Kind::User(User::UnsupportedRequestMethod) => "request has unsupported HTTP method", #[cfg(feature = "http1")] Kind::User(User::UnsupportedStatusCode) => { "response has 1xx status code, not supported by server" } #[cfg(any(feature = "http1", feature = "http2"))] + #[cfg(feature = "client")] Kind::User(User::AbsoluteUriRequired) => "client requires absolute-form URIs", Kind::User(User::NoUpgrade) => "no upgrade available", #[cfg(feature = "http1")] diff --git a/src/headers.rs b/src/headers.rs index f1663b972a..9fc2a542c1 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -3,7 +3,8 @@ use bytes::BytesMut; use http::header::CONTENT_LENGTH; use http::header::{HeaderValue, ValueIter}; #[cfg(feature = "http2")] -use http::method::Method; +#[cfg(feature = "client")] +use http::Method; use http::HeaderMap; #[cfg(feature = "http1")] @@ -65,6 +66,7 @@ pub fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>) -> Op } #[cfg(feature = "http2")] +#[cfg(feature = "client")] pub fn method_has_defined_payload_semantics(method: &Method) -> bool { match *method { Method::GET | Method::HEAD | Method::DELETE | Method::CONNECT => false, diff --git a/src/lib.rs b/src/lib.rs index 35c04bf12f..9680c169a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,9 +71,14 @@ pub mod upgrade; cfg_any_http! { mod headers; mod proto; - pub mod client; pub mod server; - pub use crate::client::Client; pub use crate::server::Server; } + +cfg_feature! { + #![all(feature = "client", any(feature = "http1", feature = "http2"))] + + pub mod client; + pub use crate::client::Client; +} diff --git a/src/proto/h1/conn.rs b/src/proto/h1/conn.rs index f24aa0a507..1d593397b7 100644 --- a/src/proto/h1/conn.rs +++ b/src/proto/h1/conn.rs @@ -1,5 +1,5 @@ use std::fmt; -use std::io::{self}; +use std::io; use std::marker::PhantomData; use bytes::{Buf, Bytes}; @@ -65,6 +65,7 @@ where self.io.set_max_buf_size(max); } + #[cfg(feature = "client")] pub fn set_read_buf_exact_size(&mut self, sz: usize) { self.io.set_read_buf_exact_size(sz); } @@ -77,6 +78,7 @@ where self.io.set_write_strategy_queue(); } + #[cfg(feature = "client")] pub fn set_title_case_headers(&mut self) { self.state.title_case_headers = true; } diff --git a/src/proto/h1/dispatch.rs b/src/proto/h1/dispatch.rs index 2f85ce7fa4..2eecc28c8d 100644 --- a/src/proto/h1/dispatch.rs +++ b/src/proto/h1/dispatch.rs @@ -1,15 +1,14 @@ use std::error::Error as StdError; use bytes::{Buf, Bytes}; -use http::{Request, Response, StatusCode}; +use http::{Request, StatusCode}; use tokio::io::{AsyncRead, AsyncWrite}; use super::{Http1Transaction, Wants}; use crate::body::{Body, DecodedLength, HttpBody}; -use crate::common::{task, Future, Never, Pin, Poll, Unpin}; +use crate::common::{task, Future, Pin, Poll, Unpin}; use crate::proto::{ - BodyLength, Conn, Dispatched, MessageHead, RequestHead, RequestLine, - ResponseHead, + BodyLength, Conn, Dispatched, MessageHead, RequestHead, }; use crate::service::HttpService; @@ -40,15 +39,17 @@ pub struct Server, B> { pub(crate) service: S, } -#[pin_project::pin_project] -pub struct Client { - callback: Option, Response>>, - #[pin] - rx: ClientRx, - rx_closed: bool, -} +cfg_client! { + #[pin_project::pin_project] + pub struct Client { + callback: Option, http::Response>>, + #[pin] + rx: ClientRx, + rx_closed: bool, + } -type ClientRx = crate::client::dispatch::Receiver, Response>; + type ClientRx = crate::client::dispatch::Receiver, http::Response>; +} impl Dispatcher where @@ -523,115 +524,117 @@ where // ===== impl Client ===== -impl Client { - pub fn new(rx: ClientRx) -> Client { - Client { - callback: None, - rx, - rx_closed: false, +cfg_client! { + impl Client { + pub fn new(rx: ClientRx) -> Client { + Client { + callback: None, + rx, + rx_closed: false, + } } } -} -impl Dispatch for Client -where - B: HttpBody, -{ - type PollItem = RequestHead; - type PollBody = B; - type PollError = Never; - type RecvItem = ResponseHead; - - fn poll_msg( - self: Pin<&mut Self>, - cx: &mut task::Context<'_>, - ) -> Poll>> { - let this = self.project(); - debug_assert!(!*this.rx_closed); - match this.rx.poll_next(cx) { - Poll::Ready(Some((req, mut cb))) => { - // check that future hasn't been canceled already - match cb.poll_canceled(cx) { - Poll::Ready(()) => { - trace!("request canceled"); - Poll::Ready(None) - } - Poll::Pending => { - let (parts, body) = req.into_parts(); - let head = RequestHead { - version: parts.version, - subject: RequestLine(parts.method, parts.uri), - headers: parts.headers, - }; - *this.callback = Some(cb); - Poll::Ready(Some(Ok((head, body)))) + impl Dispatch for Client + where + B: HttpBody, + { + type PollItem = RequestHead; + type PollBody = B; + type PollError = crate::common::Never; + type RecvItem = crate::proto::ResponseHead; + + fn poll_msg( + self: Pin<&mut Self>, + cx: &mut task::Context<'_>, + ) -> Poll>> { + let this = self.project(); + debug_assert!(!*this.rx_closed); + match this.rx.poll_next(cx) { + Poll::Ready(Some((req, mut cb))) => { + // check that future hasn't been canceled already + match cb.poll_canceled(cx) { + Poll::Ready(()) => { + trace!("request canceled"); + Poll::Ready(None) + } + Poll::Pending => { + let (parts, body) = req.into_parts(); + let head = RequestHead { + version: parts.version, + subject: crate::proto::RequestLine(parts.method, parts.uri), + headers: parts.headers, + }; + *this.callback = Some(cb); + Poll::Ready(Some(Ok((head, body)))) + } } } + Poll::Ready(None) => { + // user has dropped sender handle + trace!("client tx closed"); + *this.rx_closed = true; + Poll::Ready(None) + } + Poll::Pending => Poll::Pending, } - Poll::Ready(None) => { - // user has dropped sender handle - trace!("client tx closed"); - *this.rx_closed = true; - Poll::Ready(None) - } - Poll::Pending => Poll::Pending, } - } - fn recv_msg(&mut self, msg: crate::Result<(Self::RecvItem, Body)>) -> crate::Result<()> { - match msg { - Ok((msg, body)) => { - if let Some(cb) = self.callback.take() { - let mut res = Response::new(body); - *res.status_mut() = msg.subject; - *res.headers_mut() = msg.headers; - *res.version_mut() = msg.version; - cb.send(Ok(res)); - Ok(()) - } else { - // Getting here is likely a bug! An error should have happened - // in Conn::require_empty_read() before ever parsing a - // full message! - Err(crate::Error::new_unexpected_message()) + fn recv_msg(&mut self, msg: crate::Result<(Self::RecvItem, Body)>) -> crate::Result<()> { + match msg { + Ok((msg, body)) => { + if let Some(cb) = self.callback.take() { + let mut res = http::Response::new(body); + *res.status_mut() = msg.subject; + *res.headers_mut() = msg.headers; + *res.version_mut() = msg.version; + cb.send(Ok(res)); + Ok(()) + } else { + // Getting here is likely a bug! An error should have happened + // in Conn::require_empty_read() before ever parsing a + // full message! + Err(crate::Error::new_unexpected_message()) + } } - } - Err(err) => { - if let Some(cb) = self.callback.take() { - cb.send(Err((err, None))); - Ok(()) - } else if !self.rx_closed { - self.rx.close(); - if let Some((req, cb)) = self.rx.try_recv() { - trace!("canceling queued request with connection error: {}", err); - // in this case, the message was never even started, so it's safe to tell - // the user that the request was completely canceled - cb.send(Err((crate::Error::new_canceled().with(err), Some(req)))); + Err(err) => { + if let Some(cb) = self.callback.take() { + cb.send(Err((err, None))); Ok(()) + } else if !self.rx_closed { + self.rx.close(); + if let Some((req, cb)) = self.rx.try_recv() { + trace!("canceling queued request with connection error: {}", err); + // in this case, the message was never even started, so it's safe to tell + // the user that the request was completely canceled + cb.send(Err((crate::Error::new_canceled().with(err), Some(req)))); + Ok(()) + } else { + Err(err) + } } else { Err(err) } - } else { - Err(err) } } } - } - fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { - match self.callback { - Some(ref mut cb) => match cb.poll_canceled(cx) { - Poll::Ready(()) => { - trace!("callback receiver has dropped"); - Poll::Ready(Err(())) - } - Poll::Pending => Poll::Ready(Ok(())), - }, - None => Poll::Ready(Err(())), + fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll> { + match self.callback { + Some(ref mut cb) => match cb.poll_canceled(cx) { + Poll::Ready(()) => { + trace!("callback receiver has dropped"); + Poll::Ready(Err(())) + } + Poll::Pending => Poll::Ready(Ok(())), + }, + None => Poll::Ready(Err(())), + } } - } - fn should_poll(&self) -> bool { - self.callback.is_none() + fn should_poll(&self) -> bool { + self.callback.is_none() + } } } diff --git a/src/proto/h1/io.rs b/src/proto/h1/io.rs index d3d84d0a87..118ded6e67 100644 --- a/src/proto/h1/io.rs +++ b/src/proto/h1/io.rs @@ -84,6 +84,7 @@ where self.write_buf.max_buf_size = max; } + #[cfg(feature = "client")] pub fn set_read_buf_exact_size(&mut self, sz: usize) { self.read_buf_strategy = ReadStrategy::Exact(sz); } @@ -317,6 +318,7 @@ enum ReadStrategy { next: usize, max: usize, }, + #[cfg(feature = "client")] Exact(usize), } @@ -332,6 +334,7 @@ impl ReadStrategy { fn next(&self) -> usize { match *self { ReadStrategy::Adaptive { next, .. } => next, + #[cfg(feature = "client")] ReadStrategy::Exact(exact) => exact, } } @@ -339,38 +342,42 @@ impl ReadStrategy { fn max(&self) -> usize { match *self { ReadStrategy::Adaptive { max, .. } => max, + #[cfg(feature = "client")] ReadStrategy::Exact(exact) => exact, } } fn record(&mut self, bytes_read: usize) { - if let ReadStrategy::Adaptive { - ref mut decrease_now, - ref mut next, - max, - .. - } = *self - { - if bytes_read >= *next { - *next = cmp::min(incr_power_of_two(*next), max); - *decrease_now = false; - } else { - let decr_to = prev_power_of_two(*next); - if bytes_read < decr_to { - if *decrease_now { - *next = cmp::max(decr_to, INIT_BUFFER_SIZE); - *decrease_now = false; + match *self { + ReadStrategy::Adaptive { + ref mut decrease_now, + ref mut next, + max, + .. + } => { + if bytes_read >= *next { + *next = cmp::min(incr_power_of_two(*next), max); + *decrease_now = false; + } else { + let decr_to = prev_power_of_two(*next); + if bytes_read < decr_to { + if *decrease_now { + *next = cmp::max(decr_to, INIT_BUFFER_SIZE); + *decrease_now = false; + } else { + // Decreasing is a two "record" process. + *decrease_now = true; + } } else { - // Decreasing is a two "record" process. - *decrease_now = true; + // A read within the current range should cancel + // a potential decrease, since we just saw proof + // that we still need this size. + *decrease_now = false; } - } else { - // A read within the current range should cancel - // a potential decrease, since we just saw proof - // that we still need this size. - *decrease_now = false; } - } + }, + #[cfg(feature = "client")] + ReadStrategy::Exact(_) => (), } } } diff --git a/src/proto/h1/mod.rs b/src/proto/h1/mod.rs index 5653d950b1..bee88ea804 100644 --- a/src/proto/h1/mod.rs +++ b/src/proto/h1/mod.rs @@ -19,7 +19,10 @@ mod io; mod role; pub(crate) type ServerTransaction = role::Server; -pub(crate) type ClientTransaction = role::Client; + +cfg_client! { + pub(crate) type ClientTransaction = role::Client; +} pub(crate) trait Http1Transaction { type Incoming; diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 41b8e1b0c8..069232dffe 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -10,7 +10,7 @@ use tokio::io::{AsyncRead, AsyncWrite}; use super::{decode_content_length, ping, PipeToSendStream, SendBuf}; use crate::body::HttpBody; -use crate::common::{task, Exec, Future, Never, Pin, Poll}; +use crate::common::{task, exec::Exec, Future, Never, Pin, Poll}; use crate::headers; use crate::proto::Dispatched; use crate::{Body, Request, Response}; diff --git a/src/proto/h2/mod.rs b/src/proto/h2/mod.rs index bc1b128400..e8f5a3cbc3 100644 --- a/src/proto/h2/mod.rs +++ b/src/proto/h2/mod.rs @@ -13,11 +13,14 @@ use crate::body::{DecodedLength, HttpBody}; use crate::common::{task, Future, Pin, Poll}; use crate::headers::content_length_parse_all; -pub(crate) mod client; pub(crate) mod ping; pub(crate) mod server; -pub(crate) use self::client::ClientTask; +cfg_client! { + pub(crate) mod client; + pub(crate) use self::client::ClientTask; +} + pub(crate) use self::server::Server; /// Default initial stream window size defined in HTTP2 spec. diff --git a/src/proto/h2/ping.rs b/src/proto/h2/ping.rs index b3af976920..7cbd23ed21 100644 --- a/src/proto/h2/ping.rs +++ b/src/proto/h2/ping.rs @@ -236,6 +236,7 @@ impl Recorder { /// If the incoming stream is already closed, convert self into /// a disabled reporter. + #[cfg(feature = "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 df55baee22..2ad207c1a6 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -3,7 +3,10 @@ cfg_http1! { pub(crate) mod h1; - pub(crate) use self::h1::{dispatch, Conn, ServerTransaction}; + pub(crate) use self::h1::{Conn, ServerTransaction}; + + #[cfg(feature = "client")] + pub(crate) use self::h1::dispatch; } cfg_http2! { @@ -31,6 +34,7 @@ pub struct RequestLine(pub http::Method, pub http::Uri); /// An incoming response message. #[cfg(feature = "http1")] +#[cfg(feature = "client")] pub type ResponseHead = MessageHead; #[derive(Debug)] diff --git a/src/service/mod.rs b/src/service/mod.rs index 137aecea52..315d7a0ce1 100644 --- a/src/service/mod.rs +++ b/src/service/mod.rs @@ -40,13 +40,18 @@ pub use tower_service::Service; mod http; mod make; #[cfg(any(feature = "http1", feature = "http2"))] +#[cfg(feature = "client")] mod oneshot; mod util; pub(crate) use self::http::HttpService; #[cfg(any(feature = "http1", feature = "http2"))] -pub(crate) use self::make::{MakeConnection, MakeServiceRef}; +#[cfg(feature = "client")] +pub(crate) use self::make::MakeConnection; #[cfg(any(feature = "http1", feature = "http2"))] +pub(crate) use self::make::MakeServiceRef; +#[cfg(any(feature = "http1", feature = "http2"))] +#[cfg(feature = "client")] pub(crate) use self::oneshot::{oneshot, Oneshot}; pub use self::make::make_service_fn;