Skip to content

Commit

Permalink
no need to rename path
Browse files Browse the repository at this point in the history
it's actually "path and query and fragment"  but "path" is a bit easier to read
  • Loading branch information
jbr committed Dec 5, 2020
1 parent eecbc57 commit f066c50
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/server/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ where
}

fn url_from_httparse_req(req: &httparse::Request<'_, '_>) -> http_types::Result<Url> {
let path_and_query = req.path.ok_or_else(|| format_err!("No uri found"))?;
let path = req.path.ok_or_else(|| format_err!("No uri found"))?;

let host = req
.headers
Expand All @@ -142,12 +142,12 @@ fn url_from_httparse_req(req: &httparse::Request<'_, '_>) -> http_types::Result<

let host = std::str::from_utf8(host)?;

if path_and_query.starts_with("http://") || path_and_query.starts_with("https://") {
Ok(Url::parse(path_and_query)?)
} else if path_and_query.starts_with('/') {
Ok(Url::parse(&format!("http://{}{}", host, path_and_query))?)
if path.starts_with("http://") || path.starts_with("https://") {
Ok(Url::parse(path)?)
} else if path.starts_with('/') {
Ok(Url::parse(&format!("http://{}{}", host, path))?)
} else if req.method.unwrap().eq_ignore_ascii_case("connect") {
Ok(Url::parse(&format!("http://{}/", path_and_query))?)
Ok(Url::parse(&format!("http://{}/", path))?)
} else {
Err(format_err!("unexpected uri format"))
}
Expand Down

0 comments on commit f066c50

Please sign in to comment.