Skip to content

Commit b66e39d

Browse files
committed
build(feature): drop redundant sync_wrapper
1 parent d15b2d5 commit b66e39d

5 files changed

Lines changed: 65 additions & 58 deletions

File tree

Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ deflate = ["tower-http/decompression-deflate"]
4242
json = ["dep:serde_json"]
4343

4444
# Enable multipart/form-data support.
45-
multipart = ["dep:mime_guess"]
45+
multipart = ["dep:mime_guess", "dep:sync_wrapper"]
4646

4747
# Enable hickory DNS resolver.
4848
hickory-dns = ["dep:hickory-resolver"]
4949

5050
# Enable streaming support.
51-
stream = ["tokio/fs", "dep:tokio-util"]
51+
stream = ["tokio/fs", "dep:tokio-util", "dep:sync_wrapper"]
5252

5353
# Enable SOCKS proxy support.
5454
socks = ["dep:tokio-socks"]
@@ -71,7 +71,6 @@ url = "2.5"
7171
serde = { version = "1.0", features = ["derive"] }
7272
serde_urlencoded = "0.7.1"
7373
tower = { version = "0.5.2", default-features = false, features = ["timeout", "util", "retry"] }
74-
sync_wrapper = { version = "1.0", features = ["futures"] }
7574

7675
bytes = "1.2"
7776
http = "1"
@@ -109,8 +108,11 @@ mime_guess = { version = "2.0", default-features = false, optional = true }
109108
encoding_rs = { version = "0.8", optional = true }
110109
mime = { version = "0.3.17", optional = true }
111110

112-
## root certs
113-
webpki-root-certs = { version = "1.0.0", optional = true }
111+
## sync wrapper
112+
sync_wrapper = { version = "1.0.2", features = ["futures"], optional = true }
113+
114+
## webpki root certs
115+
webpki-root-certs = { version = "1.0.2", optional = true }
114116

115117
## cookies
116118
cookie_crate = { version = "0.18", package = "cookie", optional = true }

src/client/http/aliases.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ pub type RedirectLayer = FollowRedirect<
5959
FollowRedirectPolicy,
6060
>;
6161

62-
pub type CoreResponseFuture = crate::core::client::ResponseFuture;
63-
6462
pub type GenericClientService =
6563
MapErr<Timeout<Retry<Http2RetryPolicy, RedirectLayer>>, fn(BoxError) -> BoxError>;
6664

src/client/http/future.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use url::Url;
1010

1111
use super::{
1212
Response,
13-
aliases::{BoxedClientService, CoreResponseFuture, GenericClientService},
13+
aliases::{BoxedClientService, GenericClientService},
1414
};
1515
use crate::{
1616
Body, Error,
1717
client::{body, layer::redirect::RequestUri},
18-
core::body::Incoming,
18+
core::{body::Incoming, client::future::ResponseFuture as CoreResponseFuture},
1919
error::BoxError,
2020
into_url::IntoUrlSealed,
2121
};

src/core/client/future.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::{
2+
fmt,
3+
pin::Pin,
4+
task::{self, Poll},
5+
};
6+
7+
use http::Response;
8+
9+
use crate::core::{body::Incoming, client::Error};
10+
11+
/// A `Future` that will resolve to an HTTP Response.
12+
#[must_use = "futures do nothing unless polled"]
13+
pub struct ResponseFuture {
14+
inner: Pin<Box<dyn Future<Output = Result<Response<Incoming>, Error>> + Send>>,
15+
}
16+
17+
impl ResponseFuture {
18+
#[inline]
19+
pub(super) fn new<F>(value: F) -> ResponseFuture
20+
where
21+
F: Future<Output = Result<Response<Incoming>, Error>> + Send + 'static,
22+
{
23+
ResponseFuture {
24+
inner: Box::pin(value),
25+
}
26+
}
27+
}
28+
29+
impl fmt::Debug for ResponseFuture {
30+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31+
f.pad("Future<Response>")
32+
}
33+
}
34+
35+
impl Future for ResponseFuture {
36+
type Output = Result<Response<Incoming>, Error>;
37+
38+
#[inline]
39+
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
40+
self.inner.as_mut().poll(cx)
41+
}
42+
}

src/core/client/mod.rs

Lines changed: 14 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod pool;
77
pub mod conn;
88
pub mod connect;
99
pub(super) mod dispatch;
10+
pub mod future;
1011
pub mod options;
1112
pub mod proxy;
1213

@@ -21,15 +22,15 @@ use std::{
2122
time::Duration,
2223
};
2324

24-
use futures_util::future::{self, Either, FutureExt, TryFutureExt};
25+
use future::ResponseFuture;
26+
use futures_util::future::{Either, FutureExt, TryFutureExt};
2527
use http::{
2628
HeaderValue, Method, Request, Response, Uri, Version,
2729
header::HOST,
2830
uri::{Authority, PathAndQuery, Scheme},
2931
};
3032
use http_body::Body;
3133
use pool::Ver;
32-
use sync_wrapper::SyncWrapper;
3334
use tower::util::Oneshot;
3435

3536
use crate::{
@@ -225,15 +226,6 @@ enum TrySendError<B> {
225226
Nope(Error),
226227
}
227228

228-
type ResponseWrapper =
229-
SyncWrapper<Pin<Box<dyn Future<Output = Result<Response<Incoming>, Error>> + Send>>>;
230-
231-
/// A `Future` that will resolve to an HTTP Response.
232-
#[must_use = "futures do nothing unless polled"]
233-
pub struct ResponseFuture {
234-
inner: ResponseWrapper,
235-
}
236-
237229
// ===== impl HttpClient =====
238230

239231
impl HttpClient<(), ()> {
@@ -263,17 +255,22 @@ where
263255
match req.version() {
264256
Version::HTTP_10 if is_http_connect => {
265257
warn!("CONNECT is not allowed for HTTP/1.0");
266-
return ResponseFuture::new(future::err(e!(UserUnsupportedRequestMethod)));
258+
return ResponseFuture::new(futures_util::future::err(e!(
259+
UserUnsupportedRequestMethod
260+
)));
267261
}
268262
Version::HTTP_10 | Version::HTTP_11 | Version::HTTP_2 => {}
269263
// completely unsupported HTTP version (like HTTP/0.9)!
270-
unsupported => return ResponseFuture::error_version(unsupported),
264+
_unsupported => {
265+
warn!("Request has unsupported version \"{:?}\"", _unsupported);
266+
return ResponseFuture::new(futures_util::future::err(e!(UserUnsupportedVersion)));
267+
}
271268
};
272269

273270
// Extract and normalize URI
274271
let uri = match normalize_uri(&mut req, is_http_connect) {
275272
Ok(uri) => uri,
276-
Err(err) => return ResponseFuture::new(future::err(err)),
273+
Err(err) => return ResponseFuture::new(futures_util::future::err(err)),
277274
};
278275

279276
// Extract config extensions
@@ -490,7 +487,7 @@ where
490487

491488
// The order of the `select` is depended on below...
492489

493-
match future::select(checkout, connect).await {
490+
match futures_util::future::select(checkout, connect).await {
494491
// Checkout won, connect future may have been started or not.
495492
//
496493
// If it has, let it finish and insert back into the pool,
@@ -577,7 +574,7 @@ where
577574
None => {
578575
let canceled = e!(Canceled);
579576
// HTTP/2 connection in progress.
580-
return Either::Right(future::err(canceled));
577+
return Either::Right(futures_util::future::err(canceled));
581578
}
582579
};
583580
Either::Left(
@@ -598,7 +595,7 @@ where
598595
// Another connection has already upgraded,
599596
// the pool checkout should finish up for us.
600597
let canceled = e!(Canceled, "ALPN upgraded to HTTP/2");
601-
return Either::Right(future::err(canceled));
598+
return Either::Right(futures_util::future::err(canceled));
602599
}
603600
}
604601
} else {
@@ -796,38 +793,6 @@ impl<C, B> fmt::Debug for HttpClient<C, B> {
796793
}
797794
}
798795

799-
// ===== impl ResponseFuture =====
800-
801-
impl ResponseFuture {
802-
fn new<F>(value: F) -> Self
803-
where
804-
F: Future<Output = Result<Response<Incoming>, Error>> + Send + 'static,
805-
{
806-
Self {
807-
inner: SyncWrapper::new(Box::pin(value)),
808-
}
809-
}
810-
811-
fn error_version(_ver: Version) -> Self {
812-
warn!("Request has unsupported version \"{:?}\"", _ver);
813-
ResponseFuture::new(Box::pin(future::err(e!(UserUnsupportedVersion))))
814-
}
815-
}
816-
817-
impl fmt::Debug for ResponseFuture {
818-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
819-
f.pad("Future<Response>")
820-
}
821-
}
822-
823-
impl Future for ResponseFuture {
824-
type Output = Result<Response<Incoming>, Error>;
825-
826-
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
827-
self.inner.get_mut().as_mut().poll(cx)
828-
}
829-
}
830-
831796
/// A pooled HTTP connection that can send requests
832797
struct PoolClient<B> {
833798
conn_info: Connected,

0 commit comments

Comments
 (0)