set host ip if not the domain (pr#433 review)

This commit is contained in:
yggverse 2026-04-03 08:45:56 +03:00
parent ee74fab3ca
commit 23d4167511

View file

@ -570,25 +570,28 @@ where
return Err((BAD_REQUEST, "URL contains fragment or userinfo"));
}
let host = match url.domain() {
Some(domain) => {
match url.host() {
Some(host) => match host {
Host::Domain(domain) => {
// because the gemini scheme is not special enough for WHATWG, normalize
// it ourselves
let host = Host::parse(
let d = Host::parse(
&percent_decode_str(domain)
.decode_utf8()
.or(Err((BAD_REQUEST, "Invalid URL")))?,
)
.or(Err((BAD_REQUEST, "Invalid URL")))?;
// TODO: simplify when <https://github.com/servo/rust-url/issues/586> resolved
url.set_host(Some(&host.to_string()))
.expect("invalid domain?");
Some(host)
}
None => {
url.set_host(None).expect("invalid domain?");
None
url.set_host(Some(&d.to_string())).expect("invalid domain?");
}
Host::Ipv4(ipv4_addr) => url
.set_ip_host(IpAddr::V4(ipv4_addr))
.expect("invalid IPv4?"),
Host::Ipv6(ipv6_addr) => url
.set_ip_host(IpAddr::V6(ipv6_addr))
.expect("invalid IPv6?"),
},
None => url.set_host(None).expect("invalid domain?"),
};
// do not use "contains" here since it requires the same type and does
@ -597,7 +600,7 @@ where
&& !ARGS
.hostnames
.iter()
.any(|h| host.as_ref().is_some_and(|this| this == h))
.any(|host| url.host().as_ref().is_some_and(|this| this == host))
{
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
}