From 18201a08c5cf6a5af1d22018abeeb807bbfc064e Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Fri, 30 Oct 2020 05:55:22 +0100 Subject: [PATCH] Remove Agent::set_cookie Preloading an agent with cookies can be done by providing a prepared cookie store using `AgentBuilder`. At this point, we don't want direct state mutation on the `Agent`, so this fn goes away. Context: https://github.com/algesten/ureq/issues/203#issuecomment-716385310 --- src/agent.rs | 19 +------------------ tests/https-agent.rs | 22 ++++++---------------- 2 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/agent.rs b/src/agent.rs index cc0cb82..65a3af2 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -7,7 +7,7 @@ use crate::resolve::{ArcResolver, StdResolver}; use std::time::Duration; #[cfg(feature = "cookies")] -use {crate::cookies::CookieTin, cookie::Cookie, cookie_store::CookieStore, url::Url}; +use {crate::cookies::CookieTin, cookie_store::CookieStore}; #[derive(Debug)] pub struct AgentBuilder { @@ -107,23 +107,6 @@ impl Agent { Request::new(self.clone(), method.into(), path.into()) } - /// Store a cookie in this agent. - /// - /// ``` - /// let agent = ureq::agent(); - /// - /// let cookie = ureq::Cookie::build("name", "value") - /// .secure(true) - /// .finish(); - /// agent.set_cookie(cookie, &"https://example.com/".parse().unwrap()); - /// ``` - #[cfg(feature = "cookies")] - pub fn set_cookie(&self, cookie: Cookie<'static>, url: &Url) { - self.state - .cookie_tin - .store_response_cookies(Some(cookie).into_iter(), url); - } - /// Make a GET request from this agent. pub fn get(&self, path: &str) -> Request { self.request("GET", path) diff --git a/tests/https-agent.rs b/tests/https-agent.rs index 081df17..29655be 100644 --- a/tests/https-agent.rs +++ b/tests/https-agent.rs @@ -1,36 +1,26 @@ #[cfg(feature = "tls")] -#[cfg(feature = "cookies")] #[cfg(feature = "json")] #[test] -fn agent_set_cookie() { +fn agent_set_header() { use serde::Deserialize; use std::collections::HashMap; - #[derive(Deserialize)] + #[derive(Deserialize, Debug)] struct HttpBin { headers: HashMap, } let agent = ureq::Agent::new(); - let cookie = ureq::Cookie::build("name", "value") - .domain("httpbin.org") - .secure(true) - .finish(); - agent.set_cookie(cookie, &"https://httpbin.org/".parse().unwrap()); let resp = agent .get("https://httpbin.org/get") + .set("header", "value") .set("Connection", "close") .call() .unwrap(); assert_eq!(resp.status(), 200); - assert_eq!( - "name=value", - resp.into_json_deserialize::() - .unwrap() - .headers - .get("Cookie") - .unwrap() - ); + let json = resp.into_json_deserialize::().unwrap(); + // println!("{:?}", json); + assert_eq!("value", json.headers.get("Header").unwrap()); } #[cfg(feature = "tls")]