Skip to content

Commit

Permalink
Scheme-relative URLs are no longer allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed Jan 2, 2021
1 parent c563f27 commit 1361f07
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,10 @@ async fn parse_request(stream: &mut TlsStream<TcpStream>) -> std::result::Result
}
buf = &mut request[len..];
}
let request = std::str::from_utf8(&request[..len - 2]).or(Err((59, "Invalid URL")))?;
let request = std::str::from_utf8(&request[..len - 2]).or(Err((59, "Non-UTF-8 request")))?;
log::info!("Got request for {:?}", request);

// Handle scheme-relative URLs.
let url = if request.starts_with("//") {
Url::parse(&format!("gemini:{}", request))
} else {
Url::parse(request)
}.or(Err((59, "Invalid URL")))?;
let url = Url::parse(request).or(Err((59, "Invalid URL")))?;

// Validate the URL, host and port.
if url.scheme() != "gemini" {
Expand Down

0 comments on commit 1361f07

Please sign in to comment.