Skip to content

Commit eecbc57

Browse files
committed
fix server decode regression introduced in #153
1 parent 919c05f commit eecbc57

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/server/decode.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,20 +145,7 @@ fn url_from_httparse_req(req: &httparse::Request<'_, '_>) -> http_types::Result<
145145
if path_and_query.starts_with("http://") || path_and_query.starts_with("https://") {
146146
Ok(Url::parse(path_and_query)?)
147147
} else if path_and_query.starts_with('/') {
148-
let mut url = Url::parse(&format!("http://{}/", host))?;
149-
// path might start with `//`, so set the path explicitly using `set_path`
150-
151-
let mut split = path_and_query.split("?");
152-
if let Some(path) = split.next() {
153-
url.set_path(path);
154-
} else {
155-
return Err(format_err!("unexpected uri format"));
156-
}
157-
if let Some(query) = split.next() {
158-
url.set_query(Some(query));
159-
}
160-
161-
Ok(url)
148+
Ok(Url::parse(&format!("http://{}{}", host, path_and_query))?)
162149
} else if req.method.unwrap().eq_ignore_ascii_case("connect") {
163150
Ok(Url::parse(&format!("http://{}/", path_and_query))?)
164151
} else {
@@ -244,6 +231,19 @@ mod tests {
244231
},
245232
)
246233
}
234+
#[test]
235+
fn url_for_triple_slash_path() {
236+
httparse_req(
237+
"GET ///triple/slashes HTTP/1.1\r\nHost: server.example.com:443\r\n",
238+
|req| {
239+
let url = url_from_httparse_req(&req).unwrap();
240+
assert_eq!(
241+
url.as_str(),
242+
"http://server.example.com:443///triple/slashes"
243+
);
244+
},
245+
)
246+
}
247247

248248
#[test]
249249
fn url_for_query() {
@@ -255,4 +255,18 @@ mod tests {
255255
},
256256
)
257257
}
258+
259+
#[test]
260+
fn url_for_anchor() {
261+
httparse_req(
262+
"GET /foo?bar=1#anchor HTTP/1.1\r\nHost: server.example.com:443\r\n",
263+
|req| {
264+
let url = url_from_httparse_req(&req).unwrap();
265+
assert_eq!(
266+
url.as_str(),
267+
"http://server.example.com:443/foo?bar=1#anchor"
268+
);
269+
},
270+
)
271+
}
258272
}

0 commit comments

Comments
 (0)