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
  • Loading branch information
marco-ippolito committed Jan 11, 2023
1 parent f6e402e commit 4759921
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/_http_server.js
Expand Up @@ -352,7 +352,9 @@ function writeHead(statusCode, reason, obj) {
// writeHead(statusCode[, headers])
if (!this.statusMessage)
this.statusMessage = STATUS_CODES[statusCode] || 'unknown';
obj = reason;
if (!obj) {
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 4759921

Please sign in to comment.