Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

special handling of set-cookie header. #918

Merged
merged 2 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions http/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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`
2 changes: 1 addition & 1 deletion http/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
39 changes: 37 additions & 2 deletions http/src/h1/proto/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -158,6 +158,7 @@ where
}
}
}
SET_COOKIE => is_continue = false,
_ => {}
}

Expand Down Expand Up @@ -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
}
}
Loading