implement stricter requirements for request URLs

Addresses changes in the specification, namely these stricter requirements:
0235100151/specification.gmi (L153-155)
This commit is contained in:
Johann150 2021-04-07 23:54:44 +02:00
parent 26bda4be1b
commit ba9297eabf
No known key found for this signature in database
GPG key ID: 9EE6577A2A06F8F1

View file

@ -379,11 +379,18 @@ impl RequestHandle {
let url = Url::parse(request).or(Err((59, "Invalid URL")))?;
// Validate the URL, host and port.
// Validate the URL:
// correct scheme
if url.scheme() != "gemini" {
return Err((53, "Unsupported URL scheme"));
}
// no userinfo and no fragment
if url.password().is_some() || !url.username().is_empty() || url.fragment().is_some() {
return Err((59, "URL contains fragment or userinfo"));
}
// correct host
if let Some(host) = url.host() {
// do not use "contains" here since it requires the same type and does
// not allow to check for Host<&str> if the vec contains Hostname<String>
@ -394,6 +401,7 @@ impl RequestHandle {
return Err((59, "URL does not contain a host"));
}
// correct port
if let Some(port) = url.port() {
// Validate that the port in the URL is the same as for the stream this request came in on.
if port != self.stream.get_ref().0.local_addr().unwrap().port() {