mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 12:35:28 +00:00
set host ip if not the domain (pr#433 review)
This commit is contained in:
parent
ee74fab3ca
commit
23d4167511
1 changed files with 23 additions and 20 deletions
43
src/main.rs
43
src/main.rs
|
|
@ -570,25 +570,28 @@ where
|
||||||
return Err((BAD_REQUEST, "URL contains fragment or userinfo"));
|
return Err((BAD_REQUEST, "URL contains fragment or userinfo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let host = match url.domain() {
|
match url.host() {
|
||||||
Some(domain) => {
|
Some(host) => match host {
|
||||||
// because the gemini scheme is not special enough for WHATWG, normalize
|
Host::Domain(domain) => {
|
||||||
// it ourselves
|
// because the gemini scheme is not special enough for WHATWG, normalize
|
||||||
let host = Host::parse(
|
// it ourselves
|
||||||
&percent_decode_str(domain)
|
let d = Host::parse(
|
||||||
.decode_utf8()
|
&percent_decode_str(domain)
|
||||||
.or(Err((BAD_REQUEST, "Invalid URL")))?,
|
.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
|
.or(Err((BAD_REQUEST, "Invalid URL")))?;
|
||||||
url.set_host(Some(&host.to_string()))
|
// TODO: simplify when <https://github.com/servo/rust-url/issues/586> resolved
|
||||||
.expect("invalid domain?");
|
url.set_host(Some(&d.to_string())).expect("invalid domain?");
|
||||||
Some(host)
|
}
|
||||||
}
|
Host::Ipv4(ipv4_addr) => url
|
||||||
None => {
|
.set_ip_host(IpAddr::V4(ipv4_addr))
|
||||||
url.set_host(None).expect("invalid domain?");
|
.expect("invalid IPv4?"),
|
||||||
None
|
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
|
// do not use "contains" here since it requires the same type and does
|
||||||
|
|
@ -597,7 +600,7 @@ where
|
||||||
&& !ARGS
|
&& !ARGS
|
||||||
.hostnames
|
.hostnames
|
||||||
.iter()
|
.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"));
|
return Err((PROXY_REQUEST_REFUSED, "Proxy request refused"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue