Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ae5141c

Browse filesBrowse files
marco-ippolitoRafaelGSS
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 3f9fb37 commit ae5141c
Copy full SHA for ae5141c

File tree

Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-1
lines changed
Open diff view settings
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ function writeHead(statusCode, reason, obj) {
347347
// writeHead(statusCode[, headers])
348348
if (!this.statusMessage)
349349
this.statusMessage = STATUS_CODES[statusCode] || 'unknown';
350-
obj = reason;
350+
obj ??= reason;
351351
}
352352
this.statusCode = statusCode;
353353

Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-write-head-2.js
+18Lines changed: 18 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.