mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 20:45:29 +00:00
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:
parent
26bda4be1b
commit
ba9297eabf
1 changed files with 9 additions and 1 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -379,11 +379,18 @@ impl RequestHandle {
|
||||||
|
|
||||||
let url = Url::parse(request).or(Err((59, "Invalid URL")))?;
|
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" {
|
if url.scheme() != "gemini" {
|
||||||
return Err((53, "Unsupported URL scheme"));
|
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() {
|
if let Some(host) = url.host() {
|
||||||
// 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
|
||||||
// not allow to check for Host<&str> if the vec contains Hostname<String>
|
// 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"));
|
return Err((59, "URL does not contain a host"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// correct port
|
||||||
if let Some(port) = url.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.
|
// 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() {
|
if port != self.stream.get_ref().0.local_addr().unwrap().port() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue