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 0583c3d

Browse filesBrowse files
marco-ippolitoaduh95
authored andcommitted
http: coerce content-length to number
PR-URL: #57458 Fixes: #57456 Reviewed-By: Tim Perry <pimterry@gmail.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 43bea6b commit 0583c3d
Copy full SHA for 0583c3d

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

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

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ function matchHeader(self, state, field, value) {
650650
break;
651651
case 'content-length':
652652
state.contLen = true;
653-
self._contentLength = value;
653+
self._contentLength = +value;
654654
self._removedContLen = false;
655655
break;
656656
case 'date':
Collapse file

‎test/parallel/test-http-content-length-mismatch.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-content-length-mismatch.js
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,23 @@ function shouldThrowOnFewerBytes() {
7878
shouldThrowOnMoreBytes();
7979
shouldNotThrow();
8080
shouldThrowOnFewerBytes();
81+
82+
83+
{
84+
const server = http.createServer(common.mustCall((req, res) => {
85+
res.strictContentLength = true;
86+
// Pass content-length as string
87+
res.setHeader('content-length', '5');
88+
res.end('12345');
89+
}));
90+
91+
92+
server.listen(0, common.mustCall(() => {
93+
http.get({ port: server.address().port }, common.mustCall((res) => {
94+
res.resume().on('end', common.mustCall(() => {
95+
assert.strictEqual(res.statusCode, 200);
96+
server.close();
97+
}));
98+
}));
99+
}));
100+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.