diff --git a/lib/_http_client.js b/lib/_http_client.js index e073e973bbf205..de7b01cbd1b9bd 100644 --- a/lib/_http_client.js +++ b/lib/_http_client.js @@ -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'); diff --git a/test/parallel/test-http-client-timeout-option.js b/test/parallel/test-http-client-timeout-option.js index 6741fbe0bd1e35..6351a2ca4a3ae1 100644 --- a/test/parallel/test-http-client-timeout-option.js +++ b/test/parallel/test-http-client-timeout-option.js @@ -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,