http: validate timeout in ClientRequest()
Validate the timeout option in the ClientRequest() constructor to prevent asynchronously thrown validation errors. PR-URL: https://github.com/nodejs/node/pull/26214 Fixes: https://github.com/nodejs/node/issues/26143 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
4900863043
commit
907941d48e
@ -140,7 +140,9 @@ function ClientRequest(input, options, cb) {
|
||||
var setHost = (options.setHost === undefined || Boolean(options.setHost));
|
||||
|
||||
this.socketPath = options.socketPath;
|
||||
this.timeout = options.timeout;
|
||||
|
||||
if (options.timeout !== undefined)
|
||||
this.timeout = validateTimerDuration(options.timeout, 'timeout');
|
||||
|
||||
var method = options.method;
|
||||
var methodIsString = (typeof method === 'string');
|
||||
|
@ -3,6 +3,10 @@ const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
|
||||
assert.throws(() => {
|
||||
http.request({ timeout: null });
|
||||
}, /The "timeout" argument must be of type number/);
|
||||
|
||||
const options = {
|
||||
method: 'GET',
|
||||
port: undefined,
|
||||
|
Loading…
x
Reference in New Issue
Block a user