mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
http: coerce content-length to number
PR-URL: https://github.com/nodejs/node/pull/57458 Fixes: https://github.com/nodejs/node/issues/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>
This commit is contained in:
parent
2cb1d07e0f
commit
fef180c8a2
|
|
@ -650,7 +650,7 @@ function matchHeader(self, state, field, value) {
|
|||
break;
|
||||
case 'content-length':
|
||||
state.contLen = true;
|
||||
self._contentLength = value;
|
||||
self._contentLength = +value;
|
||||
self._removedContLen = false;
|
||||
break;
|
||||
case 'date':
|
||||
|
|
|
|||
|
|
@ -78,3 +78,23 @@ function shouldThrowOnFewerBytes() {
|
|||
shouldThrowOnMoreBytes();
|
||||
shouldNotThrow();
|
||||
shouldThrowOnFewerBytes();
|
||||
|
||||
|
||||
{
|
||||
const server = http.createServer(common.mustCall((req, res) => {
|
||||
res.strictContentLength = true;
|
||||
// Pass content-length as string
|
||||
res.setHeader('content-length', '5');
|
||||
res.end('12345');
|
||||
}));
|
||||
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
http.get({ port: server.address().port }, common.mustCall((res) => {
|
||||
res.resume().on('end', common.mustCall(() => {
|
||||
assert.strictEqual(res.statusCode, 200);
|
||||
server.close();
|
||||
}));
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user