fix bug in combining query strings

This commit is contained in:
Martin Algesten
2018-06-22 16:00:18 +02:00
parent f7c1751f3a
commit 919eab2f12
2 changed files with 11 additions and 7 deletions

View File

@@ -30,12 +30,7 @@ impl ConnectionPool {
let hostname = url.host_str().unwrap_or("localhost"); // is localhost a good alternative?
let query_string = match (url.query(), request.query.len() > 0) {
(Some(urlq), true) => format!("?{}{}", urlq, request.query),
(Some(urlq), false) => format!("?{}", urlq),
(None, true) => format!("?{}", request.query),
(None, false) => "".to_string(),
};
let query_string = combine_query(&url, &request.query);
let is_secure = url.scheme().eq_ignore_ascii_case("https");
@@ -197,3 +192,12 @@ fn match_cookies<'a>(jar: &'a CookieJar, domain: &str, path: &str, is_secure: bo
.map(|o| o.unwrap())
.collect()
}
fn combine_query(url: &Url, query: &QString) -> String {
match (url.query(), query.len() > 0) {
(Some(urlq), true) => format!("?{}&{}", urlq, query),
(Some(urlq), false) => format!("?{}", urlq),
(None, true) => format!("?{}", query),
(None, false) => "".to_string(),
}
}

View File

@@ -49,5 +49,5 @@ fn query_in_path_and_req() {
let vec = resp.to_write_vec();
let s = String::from_utf8_lossy(&vec);
println!("{}", s);
assert!(s.contains("GET /query_in_path_and_req?foo=barbaz=1%202%203 HTTP/1.1"))
assert!(s.contains("GET /query_in_path_and_req?foo=bar&baz=1%202%203 HTTP/1.1"))
}