diff --git a/Cargo.toml b/Cargo.toml index f4edf3203..665f89e4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,6 @@ url = "2.5" serde = { version = "1.0", features = ["derive"] } serde_urlencoded = "0.7.1" tower = { version = "0.5.2", default-features = false, features = ["timeout", "util", "retry"] } -tower-http = { version = "0.6.6", default-features = false, optional = true } tower-service = "0.3" sync_wrapper = { version = "1.0", features = ["futures"] } @@ -78,7 +77,6 @@ bytes = "1.2" http = "1" http-body = "1" tokio = { version = "1", default-features = false, features = ["net","time","rt"] } -atomic-waker = "1.1.2" futures-channel = "0.3.31" futures-util = { version = "0.3.31", default-features = false } http2 = { version = "0.5.4", features = ["unstable"]} @@ -86,7 +84,6 @@ http-body-util = "0.1" httparse = "1.9" pin-project-lite = "0.2.4" smallvec = { version = "1.12", features = ["const_generics", "const_new"] } -tracing = { version = "0.1", default-features = false, features = ["std"], optional = true } want = "0.3" socket2 = { version = "0.5.10", features = ["all"] } percent-encoding = "2.3" @@ -120,6 +117,9 @@ webpki-root-certs = { version = "1.0.0", optional = true } cookie_crate = { version = "0.18", package = "cookie", optional = true } cookie_store = { version = "0.21", features = ["preserve_order"], optional = true } +## tower http +tower-http = { version = "0.6.6", default-features = false, optional = true } + ## tokio util tokio-util = { version = "0.7.15", default-features = false, features = ["codec","io"], optional = true } @@ -132,6 +132,9 @@ tokio-tungstenite = { version = "0.27.0", default-features = false, features = [ ## hickory-dns hickory-resolver = { version = "0.25.2", optional = true } +## tracing +tracing = { version = "0.1", default-features = false, features = ["std"], optional = true } + ## windows system proxy [target.'cfg(windows)'.dependencies] windows-registry = { version = "0.5.2", optional = true } @@ -140,7 +143,7 @@ windows-registry = { version = "0.5.2", optional = true } [target.'cfg(target_os = "macos")'.dependencies] system-configuration = { version = "0.6.1", optional = true } -## Interface binding +## interface binding [target.'cfg(any(target_os = "ios", target_os = "visionos", target_os = "macos", target_os = "tvos", target_os = "watchos", target = "illumos", target = "solaris"))'.dependencies] libc = "0.2.173" diff --git a/src/core/client/dispatch.rs b/src/core/client/dispatch.rs index 9ad579f0a..60100dd97 100644 --- a/src/core/client/dispatch.rs +++ b/src/core/client/dispatch.rs @@ -161,7 +161,8 @@ impl Receiver { } pub(crate) fn try_recv(&mut self) -> Option<(T, Callback)> { - match crate::core::common::task::now_or_never(self.inner.recv()) { + use futures_util::FutureExt; + match self.inner.recv().now_or_never() { Some(Some(mut env)) => env.0.take(), _ => None, } diff --git a/src/core/common/either.rs b/src/core/common/either.rs deleted file mode 100644 index 4f88daf5d..000000000 --- a/src/core/common/either.rs +++ /dev/null @@ -1,47 +0,0 @@ -use std::{ - future::Future, - pin::Pin, - task::{Context, Poll}, -}; - -use pin_project_lite::pin_project; - -pin_project! { - /// One of two possible futures that have the same output type. - #[project = EitherProj] - pub(crate) enum Either { - Left { - #[pin] - fut: F1 - }, - Right { - #[pin] - fut: F2, - }, - } -} - -impl Either { - pub(crate) fn left(fut: F1) -> Self { - Either::Left { fut } - } - - pub(crate) fn right(fut: F2) -> Self { - Either::Right { fut } - } -} - -impl Future for Either -where - F1: Future, - F2: Future, -{ - type Output = F1::Output; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match self.project() { - EitherProj::Left { fut } => fut.poll(cx), - EitherProj::Right { fut } => fut.poll(cx), - } - } -} diff --git a/src/core/common/mod.rs b/src/core/common/mod.rs index 691ed280c..5709bc6e4 100644 --- a/src/core/common/mod.rs +++ b/src/core/common/mod.rs @@ -1,5 +1,4 @@ pub(crate) mod buf; -pub(crate) mod either; pub(crate) mod io; pub(crate) mod task; pub(crate) mod time; diff --git a/src/core/common/task.rs b/src/core/common/task.rs index 22b1fbd7b..41671b145 100644 --- a/src/core/common/task.rs +++ b/src/core/common/task.rs @@ -7,17 +7,3 @@ pub(crate) fn yield_now(cx: &mut Context<'_>) -> Poll cx.waker().wake_by_ref(); Poll::Pending } - -/// Poll the future once and return `Some` if it is ready, else `None`. -/// -/// If the future wasn't ready, the future likely can't be driven to completion any more: the -/// polling uses a no-op waker, so knowledge of what the pending future was waiting for is lost. -pub(crate) fn now_or_never(fut: F) -> Option { - let waker = std::task::Waker::noop(); - let mut cx = Context::from_waker(waker); - let fut = std::pin::pin!(fut); - match fut.poll(&mut cx) { - Poll::Ready(res) => Some(res), - Poll::Pending => None, - } -} diff --git a/src/core/common/watch.rs b/src/core/common/watch.rs index 90cc8dcd4..4ccd2de96 100644 --- a/src/core/common/watch.rs +++ b/src/core/common/watch.rs @@ -12,7 +12,7 @@ use std::{ task, }; -use atomic_waker::AtomicWaker; +use futures_util::task::AtomicWaker; type Value = usize; diff --git a/src/core/proto/h2/client.rs b/src/core/proto/h2/client.rs index 7c3144d70..b5476a495 100644 --- a/src/core/proto/h2/client.rs +++ b/src/core/proto/h2/client.rs @@ -14,7 +14,7 @@ use futures_channel::{ oneshot, }; use futures_util::{ - future::FusedFuture, + future::{Either, FusedFuture}, stream::{FusedStream, Stream}, }; use http::{Method, Request, Response, StatusCode}; @@ -33,7 +33,7 @@ use super::{ use crate::core::{ body::Incoming as IncomingBody, client::dispatch::{self, Callback, SendWhen, TrySendError}, - common::{either::Either, io::Compat, time::Time}, + common::{io::Compat, time::Time}, error::BoxError, ext::{Protocol, RequestConfig, RequestOriginalHeaders}, proto::{Dispatched, h2::UpgradedSendStream, headers}, @@ -225,9 +225,9 @@ where let (recorder, ponger) = ping::channel(pp, ping_config, timer); let conn: Conn<_, B> = Conn::new(ponger, conn); - (Either::left(conn), recorder) + (Either::Left(conn), recorder) } else { - (Either::right(conn), ping::disabled()) + (Either::Right(conn), ping::disabled()) }; let conn: ConnMapErr = ConnMapErr { conn,