From e9aa25d22f1b4c1b5637cdbc0c03a768ae20b95c Mon Sep 17 00:00:00 2001 From: One <43485962+c-git@users.noreply.github.com> Date: Fri, 12 Jul 2024 18:57:59 -0400 Subject: [PATCH] feat: provide access to cookies on response Resolved dead_code warning and was useful even if not to me --- src/wasm/response.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/wasm/response.rs b/src/wasm/response.rs index 47a90d04d..bec27afe6 100644 --- a/src/wasm/response.rs +++ b/src/wasm/response.rs @@ -1,5 +1,7 @@ use std::fmt; +#[cfg(feature = "cookies")] +use crate::cookie; use bytes::Bytes; use http::{HeaderMap, StatusCode}; use js_sys::Uint8Array; @@ -72,6 +74,19 @@ impl Response { .ok() } + /// Retrieve the cookies contained in the response. + /// + /// Note that invalid 'Set-Cookie' headers will be ignored. + /// + /// # Optional + /// + /// This requires the optional `cookies` feature to be enabled. + #[cfg(feature = "cookies")] + #[cfg_attr(docsrs, doc(cfg(feature = "cookies")))] + pub fn cookies<'a>(&'a self) -> impl Iterator> + 'a { + cookie::extract_response_cookies(self.http.headers()).filter_map(Result::ok) + } + /// Get the final `Url` of this `Response`. #[inline] pub fn url(&self) -> &Url {