From c5c40cf138e7760e21fca88e06c17dae23c9167c Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Wed, 24 Mar 2021 17:48:27 +0100 Subject: [PATCH] Stop percent encoding cookies --- Cargo.toml | 2 +- src/unit.rs | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b755086..fe3f255 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ socks-proxy = ["socks"] [dependencies] base64 = "0.13" chunked_transfer = "1.2.0" -cookie = { version = "0.15", features = ["percent-encode"], optional = true} +cookie = { version = "0.15", deafult-features = false, optional = true} once_cell = "1" url = "2" socks = { version = "0.3.2", optional = true } diff --git a/src/unit.rs b/src/unit.rs index 99f63c7..516a2fb 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -301,7 +301,7 @@ fn extract_cookies(agent: &Agent, url: &Url) -> Option
{ .cookie_tin .get_request_cookies(url) .iter() - .map(|c| c.encoded().to_string()) + .map(|c| c.to_string()) .collect::>() .join(";"); match header_value.as_str() { @@ -431,6 +431,9 @@ fn save_cookies(unit: &Unit, resp: &Response) { #[cfg(test)] #[cfg(feature = "cookies")] mod tests { + use cookie::Cookie; + use cookie_store::CookieStore; + use super::*; use crate::Agent; @@ -458,4 +461,19 @@ mod tests { || result == Some(Header::new("Cookie", order2)) ); } + + #[test] + fn cookies_not_percent_encoded() { + let empty = b""; + let mut store = CookieStore::load_json(&empty[..]).unwrap(); + let url = Url::parse("https://mydomain.com").unwrap(); + let cookie = Cookie::new("borked///", "illegal<>//"); + store.insert_raw(&cookie, &url).unwrap(); + let agent = crate::builder().cookie_store(store).build(); + let cookies = extract_cookies(&agent, &url); + assert_eq!( + cookies, + Some(Header::new("Cookie", "borked///=illegal<>//")) + ); + } }