From 4bde03588523089ae1319721429acae5dbee5980 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Wed, 19 Aug 2026 13:17:51 -0700 Subject: [PATCH] fix(http): append authentication cookies --- crates/yaak-http/src/types.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/crates/yaak-http/src/types.rs b/crates/yaak-http/src/types.rs index fbd68232..a9d85397 100644 --- a/crates/yaak-http/src/types.rs +++ b/crates/yaak-http/src/types.rs @@ -78,8 +78,19 @@ impl SendableHttpRequest { } pub fn insert_header(&mut self, header: (String, String)) { + if header.0.eq_ignore_ascii_case("cookie") { + if let Some(existing) = + self.headers.iter_mut().find(|h| h.0.eq_ignore_ascii_case("cookie")) + { + existing.1 = format!("{}; {}", existing.1, header.1); + } else { + self.headers.push(header); + } + return; + } + if let Some(existing) = - self.headers.iter_mut().find(|h| h.0.to_lowercase() == header.0.to_lowercase()) + self.headers.iter_mut().find(|h| h.0.eq_ignore_ascii_case(&header.0)) { existing.1 = header.1; } else { @@ -525,6 +536,27 @@ mod tests { assert_eq!(sendable.headers, vec![("Cookie".to_string(), "session=abc".to_string())]); } + #[test] + fn test_insert_header_appends_authentication_cookie() { + let mut request = SendableHttpRequest { + headers: vec![ + ("Cookie".to_string(), "session=abc".to_string()), + ("Cookie".to_string(), "theme=dark".to_string()), + ], + ..Default::default() + }; + + request.insert_header(("cookie".to_string(), "api_key=secret".to_string())); + + assert_eq!( + request.headers, + vec![ + ("Cookie".to_string(), "session=abc; api_key=secret".to_string()), + ("Cookie".to_string(), "theme=dark".to_string()), + ], + ); + } + #[tokio::test] async fn test_sendable_request_preserves_serialized_path_delimiters() { let request = HttpRequest {