From d80fd7b227a0edb548f59348842d207130e818b3 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Fri, 2 Feb 2024 10:22:43 +0800 Subject: [PATCH 1/2] special handling of set-cookie header. --- http/src/h1/proto/encode.rs | 39 +++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/http/src/h1/proto/encode.rs b/http/src/h1/proto/encode.rs index 18761015..93b46e5e 100644 --- a/http/src/h1/proto/encode.rs +++ b/http/src/h1/proto/encode.rs @@ -6,7 +6,7 @@ use crate::{ bytes::{Bytes, BytesMut}, date::DateTime, http::{ - header::{HeaderMap, CONNECTION, CONTENT_LENGTH, DATE, TE, TRANSFER_ENCODING, UPGRADE}, + header::{HeaderMap, CONNECTION, CONTENT_LENGTH, DATE, SET_COOKIE, TE, TRANSFER_ENCODING, UPGRADE}, response::Parts, StatusCode, Version, }, @@ -123,7 +123,7 @@ where let mut encoding = TransferCoding::eof(); for (next_name, value) in headers.drain() { - let is_continue = match next_name { + let mut is_continue = match next_name { Some(next_name) => { name = next_name; false @@ -158,6 +158,7 @@ where } } } + SET_COOKIE => is_continue = false, _ => {} } @@ -290,4 +291,38 @@ mod test { }) .await } + + #[tokio::test] + async fn multi_set_cookie() { + tokio::task::LocalSet::new() + .run_until(async { + let date = DateTimeService::new(); + let mut ctx = Context::<_, 64>::new(date.get()); + + let mut res = Response::new(BoxBody::new(Once::new(Bytes::new()))); + + res.headers_mut() + .insert(SET_COOKIE, HeaderValue::from_static("foo=foo")); + res.headers_mut() + .append(SET_COOKIE, HeaderValue::from_static("bar=bar")); + + let (parts, body) = res.into_parts(); + + let mut buf = BytesMut::new(); + ctx.encode_head(parts, &body, &mut buf).unwrap(); + + let mut header = [httparse::EMPTY_HEADER; 8]; + let mut res = httparse::Response::new(&mut header); + + let httparse::Status::Complete(_) = res.parse(buf.as_ref()).unwrap() else { + panic!("failed to parse response") + }; + + assert_eq!(header[0].name, "set-cookie"); + assert_eq!(header[0].value, b"foo=foo"); + assert_eq!(header[1].name, "set-cookie"); + assert_eq!(header[1].value, b"bar=bar"); + }) + .await + } } From 4650a458d9a3f879265273f8e116a177cdc708de Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Fri, 2 Feb 2024 10:38:18 +0800 Subject: [PATCH 2/2] bump version and changelog. --- http/CHANGES.md | 8 ++++++-- http/Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/http/CHANGES.md b/http/CHANGES.md index 7ab12de9..564181f5 100644 --- a/http/CHANGES.md +++ b/http/CHANGES.md @@ -1,11 +1,15 @@ # unreleased +# 0.2.2 +## Change +- `set-cookie` header is not folded into single line of header value anymore. + # 0.2.1 -## Changed +## Change - update `h3` to `0.0.4`. - update `h3-quinn` to `0.0.5`. # 0.2.0 -## Changed +## Change - `h1::proto::context::Context::encode_headers` does not want `Extensions` type argument anymore. It also wants `&mut HeaderMap` instead of `HeaderMap` to avoid consuming ownership of it. - update `xitca-router` to `0.2.0` diff --git a/http/Cargo.toml b/http/Cargo.toml index 7c306636..7e959002 100644 --- a/http/Cargo.toml +++ b/http/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xitca-http" -version = "0.2.1" +version = "0.2.2" edition = "2021" license = "Apache-2.0" description = "http library for xitca"