Skip to content

Commit 3e70b7d

Browse files
marco-ippolitojuanarbol
authored andcommitted
http: writeHead if statusmessage is undefined dont override headers
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>
1 parent 7c03a3d commit 3e70b7d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/_http_server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ function writeHead(statusCode, reason, obj) {
352352
// writeHead(statusCode[, headers])
353353
if (!this.statusMessage)
354354
this.statusMessage = STATUS_CODES[statusCode] || 'unknown';
355-
obj = reason;
355+
obj ??= reason;
356356
}
357357
this.statusCode = statusCode;
358358

test/parallel/test-http-write-head-2.js

+18
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,21 @@ const http = require('http');
5959
}));
6060
}));
6161
}
62+
63+
{
64+
const server = http.createServer(common.mustCall((req, res) => {
65+
res.writeHead(200, undefined, [ 'foo', 'bar' ]);
66+
res.end();
67+
}));
68+
69+
server.listen(0, common.mustCall(() => {
70+
http.get({ port: server.address().port }, common.mustCall((res) => {
71+
assert.strictEqual(res.statusMessage, 'OK');
72+
assert.strictEqual(res.statusCode, 200);
73+
assert.strictEqual(res.headers.foo, 'bar');
74+
res.resume().on('end', common.mustCall(() => {
75+
server.close();
76+
}));
77+
}));
78+
}));
79+
}

0 commit comments

Comments
 (0)