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 {