Skip to content

Commit

Permalink
Read all cookie headers to fill CookieJar (#575)
Browse files Browse the repository at this point in the history
* Read all cookie headers to fill `CookieJar`

* Format Rust code using rustfmt

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
chrislearn and github-actions[bot] authored Dec 19, 2023
1 parent 5f765a9 commit 9074b26
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions crates/core/src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::Arc;
use bytes::Bytes;
#[cfg(feature = "cookie")]
use cookie::{Cookie, CookieJar};
use http::header::{AsHeaderName, HeaderMap, HeaderValue, IntoHeaderName, CONTENT_TYPE};
use http::header::{AsHeaderName, HeaderMap, HeaderValue, IntoHeaderName, CONTENT_TYPE, COOKIE};
use http::method::Method;
pub use http::request::Parts;
use http::uri::{Scheme, Uri};
Expand Down Expand Up @@ -140,18 +140,18 @@ impl Request {

// Set the request cookies, if they exist.
#[cfg(feature = "cookie")]
let cookies = if let Some(header) = headers.get("Cookie") {
let cookies = {
let mut cookie_jar = CookieJar::new();
if let Ok(header) = header.to_str() {
for cookie_str in header.split(';').map(|s| s.trim()) {
if let Ok(cookie) = Cookie::parse_encoded(cookie_str).map(|c| c.into_owned()) {
cookie_jar.add_original(cookie);
for header in headers.get_all(COOKIE) {
if let Ok(header) = header.to_str() {
for cookie_str in header.split(';').map(|s| s.trim()) {
if let Ok(cookie) = Cookie::parse_encoded(cookie_str).map(|c| c.into_owned()) {
cookie_jar.add_original(cookie);
}
}
}
}
cookie_jar
} else {
CookieJar::new()
};

Request {
Expand Down

0 comments on commit 9074b26

Please sign in to comment.