fix: preserve headers when statusText is undefined in writeHead - #282
fix: preserve headers when statusText is undefined in writeHead#282vaibhavmashal wants to merge 1 commit into
Conversation
When res.writeHead is called with 3 arguments where statusText/reason is undefined (or not a string), ensure headers passed as the 3rd argument are preserved and merged into the response headers. Fixes expressjs#254
kilisamemarisaaa
left a comment
There was a problem hiding this comment.
This wrapper regresses another native writeHead overload. When the third argument is nullish, Node falls back to the non-string second argument as the headers:
res.writeHead(200, { 'X-Second': 'preserved' }, undefined)
res.writeHead(200, { 'X-Second': 'preserved' }, null)On Node 24.12.0, native writeHead and compression at the base behavior both preserve X-Second; at this PR's cc2c530 both calls silently drop it. The same loss occurs when compression's filter returns false, because the wrapper normalizes the arguments before the compression decision.
The existing suite still passes (61 passing, 1 pending) and lint is clean, so the new tests do not cover this overload. Could the normalization retain the second argument when headers == null (for example, use headers == null ? reason : headers) and add regression tests for both undefined and null third arguments?
|
close in favor of jshttp/on-headers#49 |
Fixes #254
Description
When
es.writeHead(statusCode, reason, headers)\ is called with 3 arguments where
eason/\statusText\ is \undefined\ (or not a string), the 3rd argument (\headers) was not recognized by \on-headers\ and got dropped.
This wraps
es.writeHead\ in \index.js\ to forward (statusCode, headers)\ when \�rguments.length > 2 && typeof reason !== 'string', ensuring response headers are properly set and preserved.
Changes
es.writeHead\ in \index.js\ to normalize 3-argument \writeHead\ calls where
eason\ is not a string.
es.writeHead(200, undefined, headers)\ and
es.writeHead(200, 'OK', headers)\ with both object and array header forms.