Skip to content

Commit

Permalink
http: writeHead if statusmessage is undefined dont override headers
Browse files Browse the repository at this point in the history
PR-URL: #46173
Fixes: #32395
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
marco-ippolito authored and juanarbol committed Jan 31, 2023
1 parent 7c03a3d commit 3e70b7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_http_server.js
Expand Up @@ -352,7 +352,7 @@ function writeHead(statusCode, reason, obj) {
// writeHead(statusCode[, headers])
if (!this.statusMessage)
this.statusMessage = STATUS_CODES[statusCode] || 'unknown';
obj = reason;
obj ??= reason;
}
this.statusCode = statusCode;

Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-http-write-head-2.js
Expand Up @@ -59,3 +59,21 @@ const http = require('http');
}));
}));
}

{
const server = http.createServer(common.mustCall((req, res) => {
res.writeHead(200, undefined, [ 'foo', 'bar' ]);
res.end();
}));

server.listen(0, common.mustCall(() => {
http.get({ port: server.address().port }, common.mustCall((res) => {
assert.strictEqual(res.statusMessage, 'OK');
assert.strictEqual(res.statusCode, 200);
assert.strictEqual(res.headers.foo, 'bar');
res.resume().on('end', common.mustCall(() => {
server.close();
}));
}));
}));
}

0 comments on commit 3e70b7d

Please sign in to comment.