Skip to content

Commit 907941d

Browse files
committed
http: validate timeout in ClientRequest()
Validate the timeout option in the ClientRequest() constructor to prevent asynchronously thrown validation errors. PR-URL: #26214 Fixes: #26143 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Wyatt Preul <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 4900863 commit 907941d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/_http_client.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ function ClientRequest(input, options, cb) {
140140
var setHost = (options.setHost === undefined || Boolean(options.setHost));
141141

142142
this.socketPath = options.socketPath;
143-
this.timeout = options.timeout;
143+
144+
if (options.timeout !== undefined)
145+
this.timeout = validateTimerDuration(options.timeout, 'timeout');
144146

145147
var method = options.method;
146148
var methodIsString = (typeof method === 'string');

test/parallel/test-http-client-timeout-option.js

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const common = require('../common');
33
const assert = require('assert');
44
const http = require('http');
55

6+
assert.throws(() => {
7+
http.request({ timeout: null });
8+
}, /The "timeout" argument must be of type number/);
9+
610
const options = {
711
method: 'GET',
812
port: undefined,

0 commit comments

Comments
 (0)