Release 2.3.3: Browsers now receive all cookies, not just the last one#60
Merged
dcrockwell merged 2 commits intomainfrom Mar 7, 2026
Merged
Release 2.3.3: Browsers now receive all cookies, not just the last one#60dcrockwell merged 2 commits intomainfrom
dcrockwell merged 2 commits intomainfrom
Conversation
## Why This Change Was Made - The mist response converter used `http_response.set_header` for every header, which calls `list.key_set` and replaces any existing header with the same name - This is correct for most headers but violates RFC 6265 for `Set-Cookie` — each cookie MUST be sent as a separate `Set-Cookie` header - Browsers do not parse comma-separated `Set-Cookie` values, so when a Dream response had multiple cookies, only the last one survived the conversion to mist format - This meant authentication flows setting both a session cookie and a CSRF cookie (or any multi-cookie scenario) would silently lose all cookies except the last one ## What Was Changed - `src/dream/servers/mist/response.gleam`: `add_header` now uses `prepend_header` (which allows duplicates) for `set-cookie` headers, and `set_header` (which replaces) for everything else — matching the Gleam standard library's own `set_cookie` convention - `src/dream/http/response.gleam`: Updated `Response` type hexdoc to clarify each cookie becomes a separate `Set-Cookie` header - `test/dream/servers/mist/response_test.gleam`: Added 7 tests covering RFC 6265 multi-cookie compliance - `test/matchers/count_mist_headers.gleam`: New matcher for verifying header counts by name - `test/matchers/extract_all_mist_header_values.gleam`: New matcher for extracting all values of a header - `CHANGELOG.md`: Added 2.3.3 entry - `gleam.toml`: Bumped version to 2.3.3 - `releases/release-2.3.3.md`: New release notes ## Note to Future Engineer - The string match on `"set-cookie"` looks fragile but is safe: `convert_header_to_tuple` lowercases all header names, and `add_cookie_header` hardcodes lowercase `"set-cookie"` — plus `prepend_header` itself lowercases the key internally, so you'd have to try pretty hard to break this - If you're wondering why `Set-Cookie` is special: RFC 7230 §3.2.2 says you can comma-fold duplicate headers into one, EXCEPT for `Set-Cookie` which RFC 6265 says you absolutely cannot — because cookie values can contain commas (in Expires dates), so browsers gave up trying to parse them that way circa 2011 and never looked back - Yes, this means the entire fix is a three-line case expression. The other 250 lines are tests. You're welcome.
Browsers now receive all cookies, not just the last one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release 2.3.3
Summary
This release fixes a bug where multiple
Set-Cookieheaders were collapsed into a single header during mist response conversion, causing browsers to only receive the last cookie in multi-cookie responses.What's Included
Bug Fix — Multiple Set-Cookie headers (PR #59)
The mist response converter used
set_headerfor all headers, which replaces existing headers with the same name. This violates RFC 6265, which requires each cookie to be sent as its ownSet-Cookieheader. Browsers don't parse comma-separatedSet-Cookievalues — they only see the first (or last) cookie.The fix uses
prepend_header(which allows duplicates) forset-cookieheaders, andset_header(which replaces) for everything else. This matches the Gleam standard library's ownset_cookieconvention.Test Coverage
count_mist_headers,extract_all_mist_header_values)Documentation
convertandResponsetype to document per-cookie header behaviorUpgrade
Full Changelog