From a90bb70ee65421e44461a0ad2f3087007c10ca13 Mon Sep 17 00:00:00 2001 From: faumaray Date: Sat, 24 Oct 2026 14:29:29 +0300 Subject: [PATCH] Let the test SOCKS proxy dial localhost at the IPv4 loopback web::tests::pictures_go_through_the_proxy_named_for_each_hop downloads http://localhost:/banner through a SOCKS5h proxy of its own and asserts that the proxy was given the name "localhost:". The test proxy then connected to that name through the system's resolver, and on a machine that resolves localhost to ::1 only (this one) the server, which listens on 127.0.0.1, was not reachable: the download timed out after 20 s. The proxy still reports the name it was given, as SOCKS5h says, and dials localhost at 127.0.0.1 like the server it stands in front of. Co-Authored-By: Claude Sonnet 5.5 --- crates/voelin-core/src/web.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/voelin-core/src/web.rs b/crates/voelin-core/src/web.rs index e464aba..c272023 100644 --- a/crates/voelin-core/src/web.rs +++ b/crates/voelin-core/src/web.rs @@ -1430,9 +1430,15 @@ pub(crate) mod tests { }; let mut port = [0u8; 2]; client.read_exact(&mut port).await.unwrap(); - let target = format!("{host}:{}", u16::from_be_bytes(port)); + let port = u16::from_be_bytes(port); + let target = format!("{host}:{port}"); targets.send(target.clone()).unwrap(); - let mut server = TcpStream::connect(target).await.unwrap(); + // The proxy resolves the name it is given (SOCKS5h). `localhost` is + // 127.0.0.1 to it, whatever this machine's resolver says: some answer + // `::1` only, and the servers of the tests listen on 127.0.0.1. + let dial = + if host == "localhost" { format!("127.0.0.1:{port}") } else { target }; + let mut server = TcpStream::connect(dial).await.unwrap(); client.write_all(&[5, 0, 0, 1, 0, 0, 0, 0, 0, 0]).await.unwrap(); let _ = tokio::io::copy_bidirectional(&mut client, &mut server).await; });