fix(http): surface res.headers['set-cookie'] as an array (#5079)#5102
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughPerry's HTTP header representation is updated to preserve multiplicity by changing ChangesHTTP Header Multiplicity and Node.js Rules
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/perry-ext-http-server/src/request.rs`:
- Around line 290-321: combined_headers_json currently joins duplicate
non-set-cookie headers with ", " and doesn't treat Cookie specially; update the
function combined_headers_json to handle key == "cookie" like set-cookie is
handled but by concatenating cookie values with "; " instead of ", ": when
encountering key == "cookie", if map.get_mut(&key) is
Some(Value::String(existing)) append "; " + value, otherwise insert
Value::String(value.clone()); keep the existing set-cookie array behavior and
existing is_single_value_header logic for other headers unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: b966bfc4-66c8-45c3-ab08-79559dc18cb7
📒 Files selected for processing (4)
crates/perry-ext-http-server/src/request.rscrates/perry-ext-http/src/client_events.rscrates/perry-ext-http/src/lib.rscrates/perry-ext-http/src/tests.rs
c7ff397 to
33f7a29
Compare
`IncomingMessage.headers` collapsed duplicate response headers into a single `HashMap<String,String>` value, so `res.headers['set-cookie']` returned only the last cookie and any repeated header lost its earlier values. Preserve header multiplicity and apply Node's `_http_incoming.js` `matchKnownFields` combination rules when building the combined `headers` view: - `set-cookie` -> **always** a string array, even for a single cookie; - single-value fields (content-length, content-type, host, ...) -> first value wins; - everything else -> duplicates joined with `, `. Client side (perry-ext-http): `IncomingMessageHandle.headers` becomes a `Vec<(String,String)>` (arrival order, multiplicity preserved); the `res.headers` getter builds the JS object via the new `build_response_headers_object`, emitting a real array for set-cookie. Server side (perry-ext-http-server): `js_node_http_im_headers_json` now builds the combined object from `raw_headers` (which already round-trips for rawHeaders/headersDistinct) via `combined_headers_json`, so server-side `req.headers['set-cookie']` is likewise an array. Verified against the issue repro (now prints `["a=1","b=2"]`); existing ext-http/ext-http-server unit tests pass.
…atchKnownFields (CodeRabbit #5079)
…le (keep lib.rs under 2000-line cap)
33f7a29 to
3ffbb56
Compare
Fixes #5079.
Problem
IncomingMessage.headerswas aHashMap<String,String>built by inserting each(name, value)pair from the response — duplicates clobbered. Sores.headers['set-cookie']returned only the last cookie string instead of the spec-mandated string array, and other repeated headers lost their earlier values.Fix
Preserve header multiplicity and apply Node's
_http_incoming.jsmatchKnownFieldscombination rules when building the combinedheadersview:set-cookie→ always a string array, even for a single cookie;content-length,content-type,host,authorization, …) → first value wins;,.Client (
perry-ext-http):IncomingMessageHandle.headersis now aVec<(String,String)>(arrival order, multiplicity preserved). Theres.headersgetter builds the JS object via the newbuild_response_headers_object, emitting a real array forset-cookie. It's the only reader of that field, so the change is contained.Server (
perry-ext-http-server):js_node_http_im_headers_jsonbuilds the combined object fromraw_headers(already round-tripped forrawHeaders/headersDistinct) viacombined_headers_json, so server-sidereq.headers['set-cookie']is likewise an array.Verification
Issue repro now prints:
(
content-type undefinedmatches Node — the repro server never sets it, confirming single-value passthrough is intact.)Existing
perry-ext-http/perry-ext-http-serverunit tests pass (23 passed, 0 failed).No version bump / changelog per maintainer instruction — to be folded in at merge.
Summary by CodeRabbit
headersrendering to follow Node.js-style known-field merging, including correct duplicate handling forcookieand other multi-value headers.set-cookieis consistently exposed as an array, and malformed or missing header data now safely falls back.