From a8ee8ab75ebf2ab2a682c09b43eb1084d4df25cf Mon Sep 17 00:00:00 2001 From: Martin Algesten Date: Fri, 30 Oct 2020 06:07:47 +0100 Subject: [PATCH] Provide AgentBuilder::cookie_store setter --- src/agent.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/agent.rs b/src/agent.rs index 3d78dba..5439c0b 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -373,6 +373,36 @@ impl AgentBuilder { self.config.tls_config = Some(TLSClientConfig(tls_config)); self } + + /// Provide the cookie store to be used for all requests using this agent. + /// + /// This is useful in two cases. First when there is a need to persist cookies + /// to some backing store, and second when there's a need to prepare the agent + /// with some pre-existing cookies. + /// + /// Example + /// ```no_run + /// use cookie_store::CookieStore; + /// use std::fs::File; + /// use std::io::BufReader; + /// + /// let file = File::open("cookies.json").unwrap(); + /// let read = BufReader::new(file); + /// + /// // Read persisted cookies from cookies.json + /// let my_store = CookieStore::load_json(read).unwrap(); + /// + /// // Cookies will be used for requests done through agent. + /// let agent = ureq::builder() + /// .cookie_store(my_store) + /// .build(); + ///; + /// ``` + #[cfg(feature = "cookies")] + pub fn cookie_store(mut self, cookie_store: CookieStore) -> Self { + self.cookie_store = Some(cookie_store); + self + } } #[cfg(feature = "tls")]