mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
http2: callback valid check before closing request
Do not close the request if callback is not a function, and throw ERR_INVALID_CALLBACK TypeError Backport-PR-URL: https://github.com/nodejs/node/pull/19229 PR-URL: https://github.com/nodejs/node/pull/19061 Fixes: https://github.com/nodejs/node/issues/18855 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
8e440115ec
commit
2bdf3ca235
|
|
@ -1763,6 +1763,8 @@ class Http2Stream extends Duplex {
|
|||
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'code', 'number');
|
||||
if (code < 0 || code > kMaxInt)
|
||||
throw new errors.RangeError('ERR_OUT_OF_RANGE', 'code');
|
||||
if (callback !== undefined && typeof callback !== 'function')
|
||||
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
||||
|
||||
// Unenroll the timeout.
|
||||
unenroll(this);
|
||||
|
|
@ -1780,8 +1782,6 @@ class Http2Stream extends Duplex {
|
|||
state.rstCode = code;
|
||||
|
||||
if (callback !== undefined) {
|
||||
if (typeof callback !== 'function')
|
||||
throw new errors.TypeError('ERR_INVALID_CALLBACK');
|
||||
this.once('close', callback);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,18 @@ server.listen(0, common.mustCall(() => {
|
|||
);
|
||||
assert.strictEqual(req.closed, false);
|
||||
|
||||
[true, 1, {}, [], null, 'test'].forEach((notFunction) => {
|
||||
common.expectsError(
|
||||
() => req.close(closeCode, notFunction),
|
||||
{
|
||||
type: TypeError,
|
||||
code: 'ERR_INVALID_CALLBACK',
|
||||
message: 'Callback must be a function'
|
||||
}
|
||||
);
|
||||
assert.strictEqual(req.closed, false);
|
||||
});
|
||||
|
||||
req.close(closeCode, common.mustCall());
|
||||
assert.strictEqual(req.closed, true);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user