Skip to content

Commit

Permalink
Revert "feat(client): Add connection capturing API to hyper-util (hyp…
Browse files Browse the repository at this point in the history
…erium#112)"

This reverts commit a77d866.
  • Loading branch information
r58Playz committed Jul 3, 2024
1 parent 8d9a542 commit 0979241
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 235 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pin-project-lite = "0.2.4"
futures-channel = { version = "0.3", optional = true }
socket2 = { version = "0.5", optional = true, features = ["all"] }
tracing = { version = "0.1", default-features = false, features = ["std"], optional = true }
tokio = { version = "1", optional = true, default-features = false }
tokio = { version = "1", optional = true, features = ["net", "rt", "time"] }
tower-service ={ version = "0.3", optional = true }
tower = { version = "0.4.1", optional = true, default-fetures = false, features = ["util"] }
wasm-bindgen = "0.2.90"
Expand Down Expand Up @@ -60,7 +60,7 @@ full = [
]

client = ["hyper/client", "dep:tracing", "dep:futures-channel", "dep:tower", "dep:tower-service"]
client-legacy = ["client", "dep:socket2", "tokio/sync"]
client-legacy = ["client", "dep:socket2"]

server = ["hyper/server"]
server-auto = ["server", "http1", "http2"]
Expand All @@ -71,7 +71,7 @@ service = ["dep:tower", "dep:tower-service"]
http1 = ["hyper/http1"]
http2 = ["hyper/http2"]

tokio = ["dep:tokio", "tokio/net", "tokio/rt", "tokio/time"]
tokio = ["dep:tokio"]

# internal features used in CI
__internal_happy_eyeballs_tests = []
Expand Down
5 changes: 0 additions & 5 deletions src/client/legacy/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use hyper::rt::Timer;
use hyper::{body::Body, Method, Request, Response, Uri, Version};
use tracing::{debug, trace, warn};

use super::connect::capture::CaptureConnectionExtension;
#[cfg(feature = "tokio")]
use super::connect::HttpConnector;
use super::connect::{Alpn, Connect, Connected, Connection};
Expand Down Expand Up @@ -270,10 +269,6 @@ where
// it returns an error, there's not much else to retry
.map_err(TrySendError::Nope)?;

req.extensions_mut()
.get_mut::<CaptureConnectionExtension>()
.map(|conn| conn.set(&pooled.conn_info));

if pooled.is_http1() {
if req.version() == Version::HTTP_2 {
warn!("Connection is HTTP/1, but request requires HTTP/2");
Expand Down
191 changes: 0 additions & 191 deletions src/client/legacy/connect/capture.rs

This file was deleted.

4 changes: 1 addition & 3 deletions src/client/legacy/connect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ pub mod dns;
#[cfg(feature = "tokio")]
mod http;

pub(crate) mod capture;
pub use capture::{capture_connection, CaptureConnection};

pub use self::sealed::Connect;

/// Describes a type returned by a connector.
Expand Down Expand Up @@ -172,6 +169,7 @@ impl Connected {

// Don't public expose that `Connected` is `Clone`, unsure if we want to
// keep that contract...
#[cfg(feature = "http2")]
pub(super) fn clone(&self) -> Connected {
Connected {
alpn: self.alpn,
Expand Down
34 changes: 1 addition & 33 deletions tests/legacy_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use http_body_util::{Empty, Full, StreamBody};
use hyper::body::Bytes;
use hyper::body::Frame;
use hyper::Request;
use hyper_util::client::legacy::connect::{capture_connection, HttpConnector};
use hyper_util::client::legacy::connect::HttpConnector;
use hyper_util::client::legacy::Client;
use hyper_util::rt::{TokioExecutor, TokioIo};

Expand Down Expand Up @@ -876,35 +876,3 @@ fn alpn_h2() {
);
drop(client);
}

#[cfg(not(miri))]
#[test]
fn capture_connection_on_client() {
let _ = pretty_env_logger::try_init();

let rt = runtime();
let connector = DebugConnector::new();

let client = Client::builder(TokioExecutor::new()).build(connector);

let server = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = server.local_addr().unwrap();
thread::spawn(move || {
let mut sock = server.accept().unwrap().0;
//drop(server);
sock.set_read_timeout(Some(Duration::from_secs(5))).unwrap();
sock.set_write_timeout(Some(Duration::from_secs(5)))
.unwrap();
let mut buf = [0; 4096];
sock.read(&mut buf).expect("read 1");
sock.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n")
.expect("write 1");
});
let mut req = Request::builder()
.uri(&*format!("http://{}/a", addr))
.body(Empty::<Bytes>::new())
.unwrap();
let captured_conn = capture_connection(&mut req);
rt.block_on(client.request(req)).expect("200 OK");
assert!(captured_conn.connection_metadata().is_some());
}

0 comments on commit 0979241

Please sign in to comment.