GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http: coerce content-length to number · nodejs/node@0583c3d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • _http_outgoing.js
  • test/parallel
    • test-http-content-length-mismatch.js
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.