diff --git a/Cargo.lock b/Cargo.lock index 8f591a3..59435ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,7 +321,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "qstring" -version = "0.5.3" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -468,7 +468,7 @@ dependencies = [ "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 1.8.4 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "qstring 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "qstring 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.20 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -556,7 +556,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "05a079dd052e7b674d21cb31cbb6c05efd56a2cd2827db7692e2f1a507ebd998" "checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930" "checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f" -"checksum qstring 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b065672875dc3551830af169852799e394361757bc2a5d9739c37815a7800c03" +"checksum qstring 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "545ec057a36a93e25fb5883baed912e4984af4e2543bbf0e3463d962e0408469" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" diff --git a/Cargo.toml b/Cargo.toml index f771d43..848b90b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ dns-lookup = "0.9.1" encoding = "0.2" lazy_static = "1" mime_guess = "1" -qstring = "0.5.3" +qstring = "0.6" native-tls = "0.1" serde_json = "1" url = "1.6" diff --git a/src/conn.rs b/src/conn.rs index cdeffef..d538dae 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -29,11 +29,14 @@ impl ConnectionPool { .unwrap_or(false); let hostname = url.host_str().unwrap_or("localhost"); // is localhost a good alternative? - let query_string = if request.query.len() > 0 { - format!("{}", request.query) - } else { - "".to_string() + + 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 is_secure = url.scheme().eq_ignore_ascii_case("https"); let cookie_headers: Vec<_> = { diff --git a/src/test/query_string.rs b/src/test/query_string.rs index 95e5b84..009461f 100644 --- a/src/test/query_string.rs +++ b/src/test/query_string.rs @@ -27,3 +27,28 @@ fn escaped_query_string() { let s = String::from_utf8_lossy(&vec); assert!(s.contains("GET /escaped_query_string?foo=bar&baz=yo%20lo HTTP/1.1")) } + +#[test] +fn query_in_path() { + test::set_handler("/query_in_path", |_req, _url| { + test::make_response(200, "OK", vec![], vec![]) + }); + let resp = get("test://host/query_in_path?foo=bar").call(); + let vec = resp.to_write_vec(); + let s = String::from_utf8_lossy(&vec); + assert!(s.contains("GET /query_in_path?foo=bar HTTP/1.1")) +} + +#[test] +fn query_in_path_and_req() { + test::set_handler("/query_in_path_and_req", |_req, _url| { + test::make_response(200, "OK", vec![], vec![]) + }); + let resp = get("test://host/query_in_path_and_req?foo=bar") + .query("baz", "1 2 3") + .call(); + 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")) +} diff --git a/src/test/simple.rs b/src/test/simple.rs index d36c2b9..70c0304 100644 --- a/src/test/simple.rs +++ b/src/test/simple.rs @@ -84,3 +84,14 @@ fn body_as_reader() { reader.read_to_string(&mut text).unwrap(); assert_eq!(text, "abcdefgh"); } + +#[test] +fn escape_path() { + test::set_handler("/escape_path%20here", |_req, _url| { + test::make_response(200, "OK", vec![], vec![]) + }); + let resp = get("test://host/escape_path here").call(); + let vec = resp.to_write_vec(); + let s = String::from_utf8_lossy(&vec); + assert!(s.contains("GET /escape_path%20here HTTP/1.1")) +}