Skip to content

Commit bb3af17

Browse files
authored
feat(client): remove higher-level hyper::Client (#2941)
This removes the following types and methods from hyper: - `Client` - `Error::is_connect()` BREAKING CHANGE: A pooling client is in the hyper-util crate.
1 parent 889fa2d commit bb3af17

File tree

14 files changed

+34
-3924
lines changed

14 files changed

+34
-3924
lines changed

src/body/body.rs

+2-91
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use http_body::{Body as HttpBody, SizeHint};
1010

1111
use super::DecodedLength;
1212
use crate::common::Future;
13-
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
14-
use crate::common::Never;
1513
use crate::common::{task, watch, Pin, Poll};
1614
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
1715
use crate::proto::h2::ping;
@@ -29,9 +27,6 @@ type TrailersSender = oneshot::Sender<HeaderMap>;
2927
#[must_use = "streams do nothing unless polled"]
3028
pub struct Body {
3129
kind: Kind,
32-
/// Keep the extra bits in an `Option<Box<Extra>>`, so that
33-
/// Body stays small in the common case (no extras needed).
34-
extra: Option<Box<Extra>>,
3530
}
3631

3732
enum Kind {
@@ -52,34 +47,6 @@ enum Kind {
5247
Ffi(crate::ffi::UserBody),
5348
}
5449

55-
struct Extra {
56-
/// Allow the client to pass a future to delay the `Body` from returning
57-
/// EOF. This allows the `Client` to try to put the idle connection
58-
/// back into the pool before the body is "finished".
59-
///
60-
/// The reason for this is so that creating a new request after finishing
61-
/// streaming the body of a response could sometimes result in creating
62-
/// a brand new connection, since the pool didn't know about the idle
63-
/// connection yet.
64-
delayed_eof: Option<DelayEof>,
65-
}
66-
67-
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
68-
type DelayEofUntil = oneshot::Receiver<Never>;
69-
70-
enum DelayEof {
71-
/// Initial state, stream hasn't seen EOF yet.
72-
#[cfg(any(feature = "http1", feature = "http2"))]
73-
#[cfg(feature = "client")]
74-
NotEof(DelayEofUntil),
75-
/// Transitions to this state once we've seen `poll` try to
76-
/// return EOF (`None`). This future is then polled, and
77-
/// when it completes, the Body finally returns EOF (`None`).
78-
#[cfg(any(feature = "http1", feature = "http2"))]
79-
#[cfg(feature = "client")]
80-
Eof(DelayEofUntil),
81-
}
82-
8350
/// A sender half created through [`Body::channel()`].
8451
///
8552
/// Useful when wanting to stream chunks from another thread.
@@ -153,7 +120,7 @@ impl Body {
153120
}
154121

155122
fn new(kind: Kind) -> Body {
156-
Body { kind, extra: None }
123+
Body { kind }
157124
}
158125

159126
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
@@ -176,62 +143,6 @@ impl Body {
176143
body
177144
}
178145

179-
#[cfg(any(feature = "http1", feature = "http2"))]
180-
#[cfg(feature = "client")]
181-
pub(crate) fn delayed_eof(&mut self, fut: DelayEofUntil) {
182-
self.extra_mut().delayed_eof = Some(DelayEof::NotEof(fut));
183-
}
184-
185-
fn take_delayed_eof(&mut self) -> Option<DelayEof> {
186-
self.extra
187-
.as_mut()
188-
.and_then(|extra| extra.delayed_eof.take())
189-
}
190-
191-
#[cfg(any(feature = "http1", feature = "http2"))]
192-
fn extra_mut(&mut self) -> &mut Extra {
193-
self.extra
194-
.get_or_insert_with(|| Box::new(Extra { delayed_eof: None }))
195-
}
196-
197-
fn poll_eof(&mut self, cx: &mut task::Context<'_>) -> Poll<Option<crate::Result<Bytes>>> {
198-
match self.take_delayed_eof() {
199-
#[cfg(any(feature = "http1", feature = "http2"))]
200-
#[cfg(feature = "client")]
201-
Some(DelayEof::NotEof(mut delay)) => match self.poll_inner(cx) {
202-
ok @ Poll::Ready(Some(Ok(..))) | ok @ Poll::Pending => {
203-
self.extra_mut().delayed_eof = Some(DelayEof::NotEof(delay));
204-
ok
205-
}
206-
Poll::Ready(None) => match Pin::new(&mut delay).poll(cx) {
207-
Poll::Ready(Ok(never)) => match never {},
208-
Poll::Pending => {
209-
self.extra_mut().delayed_eof = Some(DelayEof::Eof(delay));
210-
Poll::Pending
211-
}
212-
Poll::Ready(Err(_done)) => Poll::Ready(None),
213-
},
214-
Poll::Ready(Some(Err(e))) => Poll::Ready(Some(Err(e))),
215-
},
216-
#[cfg(any(feature = "http1", feature = "http2"))]
217-
#[cfg(feature = "client")]
218-
Some(DelayEof::Eof(mut delay)) => match Pin::new(&mut delay).poll(cx) {
219-
Poll::Ready(Ok(never)) => match never {},
220-
Poll::Pending => {
221-
self.extra_mut().delayed_eof = Some(DelayEof::Eof(delay));
222-
Poll::Pending
223-
}
224-
Poll::Ready(Err(_done)) => Poll::Ready(None),
225-
},
226-
#[cfg(any(
227-
not(any(feature = "http1", feature = "http2")),
228-
not(feature = "client")
229-
))]
230-
Some(delay_eof) => match delay_eof {},
231-
None => self.poll_inner(cx),
232-
}
233-
}
234-
235146
#[cfg(feature = "ffi")]
236147
pub(crate) fn as_ffi_mut(&mut self) -> &mut crate::ffi::UserBody {
237148
match self.kind {
@@ -313,7 +224,7 @@ impl HttpBody for Body {
313224
mut self: Pin<&mut Self>,
314225
cx: &mut task::Context<'_>,
315226
) -> Poll<Option<Result<Self::Data, Self::Error>>> {
316-
self.poll_eof(cx)
227+
self.poll_inner(cx)
317228
}
318229

319230
fn poll_trailers(

0 commit comments

Comments
 (0)