diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f4be75..2a265c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ This may lead to no listed changes for a version. ## [Unreleased] +### Fixed +* Use the default port when checking for the right port. + ## [3.3.19] - 2025-09-18 ### Fixed diff --git a/src/main.rs b/src/main.rs index 64f2e48..dea16c4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -591,16 +591,14 @@ where return Err((PROXY_REQUEST_REFUSED, "Proxy request refused")); } - // correct port + // Validate that the port in the URL is the same as for the stream this request + // came in on. if let Some(expected_port) = self.local_port_check - && let Some(port) = url.port() + && url.port().unwrap_or(DEFAULT_PORT) != expected_port { - // Validate that the port in the URL is the same as for the stream this request - // came in on. - if port != expected_port { - return Err((PROXY_REQUEST_REFUSED, "Proxy request refused")); - } + return Err((PROXY_REQUEST_REFUSED, "Proxy request refused")); } + Ok(url) } diff --git a/tests/tests.rs b/tests/tests.rs index 64e964d..92c978e 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -36,6 +36,7 @@ static PORT: AtomicU16 = AtomicU16::new(DEFAULT_PORT); struct Server { addr: SocketAddr, server: std::process::Child, + port: u16, // is set when output is collected by stop() output: Option>, } @@ -44,11 +45,10 @@ impl Server { pub fn new(args: &[&str]) -> Self { use std::net::{IpAddr, Ipv4Addr}; + let port = PORT.fetch_add(1, Ordering::SeqCst); + // generate unique port/address so tests do not clash - let addr = ( - IpAddr::V4(Ipv4Addr::LOCALHOST), - PORT.fetch_add(1, Ordering::SeqCst), - ) + let addr = (IpAddr::V4(Ipv4Addr::LOCALHOST), port) .to_socket_addrs() .unwrap() .next() @@ -84,6 +84,7 @@ impl Server { Self { addr, server, + port, output: None, } } @@ -147,7 +148,12 @@ impl Drop for Server { fn get(args: &[&str], url: &str) -> Result { let mut server = Server::new(args); - let url = Url::parse(url).unwrap(); + let mut url = Url::parse(url).unwrap(); + if url.port().is_none() { + // inject port number into URL because that is only determined + // when constructing the `Server` above. + url.set_port(Some(server.port)).unwrap(); + } let actor = Actor::default().proxy("localhost".into(), server.addr.port()); let request = actor.get(url);