mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 12:35:28 +00:00
use default port in URL port check
This commit is contained in:
parent
aadddc2c0c
commit
1536c382ab
3 changed files with 19 additions and 12 deletions
|
|
@ -10,6 +10,9 @@ This may lead to no listed changes for a version.
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* Use the default port when checking for the right port.
|
||||||
|
|
||||||
## [3.3.19] - 2025-09-18
|
## [3.3.19] - 2025-09-18
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
|
||||||
10
src/main.rs
10
src/main.rs
|
|
@ -591,16 +591,14 @@ where
|
||||||
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
|
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// correct port
|
|
||||||
if let Some(expected_port) = self.local_port_check
|
|
||||||
&& let Some(port) = url.port()
|
|
||||||
{
|
|
||||||
// Validate that the port in the URL is the same as for the stream this request
|
// Validate that the port in the URL is the same as for the stream this request
|
||||||
// came in on.
|
// came in on.
|
||||||
if port != expected_port {
|
if let Some(expected_port) = self.local_port_check
|
||||||
|
&& url.port().unwrap_or(DEFAULT_PORT) != expected_port
|
||||||
|
{
|
||||||
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
|
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(url)
|
Ok(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ static PORT: AtomicU16 = AtomicU16::new(DEFAULT_PORT);
|
||||||
struct Server {
|
struct Server {
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
server: std::process::Child,
|
server: std::process::Child,
|
||||||
|
port: u16,
|
||||||
// is set when output is collected by stop()
|
// is set when output is collected by stop()
|
||||||
output: Option<Result<(), String>>,
|
output: Option<Result<(), String>>,
|
||||||
}
|
}
|
||||||
|
|
@ -44,11 +45,10 @@ impl Server {
|
||||||
pub fn new(args: &[&str]) -> Self {
|
pub fn new(args: &[&str]) -> Self {
|
||||||
use std::net::{IpAddr, Ipv4Addr};
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
|
|
||||||
|
let port = PORT.fetch_add(1, Ordering::SeqCst);
|
||||||
|
|
||||||
// generate unique port/address so tests do not clash
|
// generate unique port/address so tests do not clash
|
||||||
let addr = (
|
let addr = (IpAddr::V4(Ipv4Addr::LOCALHOST), port)
|
||||||
IpAddr::V4(Ipv4Addr::LOCALHOST),
|
|
||||||
PORT.fetch_add(1, Ordering::SeqCst),
|
|
||||||
)
|
|
||||||
.to_socket_addrs()
|
.to_socket_addrs()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.next()
|
.next()
|
||||||
|
|
@ -84,6 +84,7 @@ impl Server {
|
||||||
Self {
|
Self {
|
||||||
addr,
|
addr,
|
||||||
server,
|
server,
|
||||||
|
port,
|
||||||
output: None,
|
output: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +148,12 @@ impl Drop for Server {
|
||||||
fn get(args: &[&str], url: &str) -> Result<Response, String> {
|
fn get(args: &[&str], url: &str) -> Result<Response, String> {
|
||||||
let mut server = Server::new(args);
|
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 actor = Actor::default().proxy("localhost".into(), server.addr.port());
|
||||||
let request = actor.get(url);
|
let request = actor.get(url);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue