mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
http: writeHead if statusmessage is undefined dont override headers
PR-URL: https://github.com/nodejs/node/pull/46173 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
3ef38c4bd7
commit
6e375b389b
@ -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;
|
||||
|
||||
|
||||
@ -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();
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user