Skip to content

Commit

Permalink
http: validate timeout in ClientRequest()
Browse files Browse the repository at this point in the history
Validate the timeout option in the ClientRequest() constructor
to prevent asynchronously thrown validation errors.

PR-URL: #26214
Fixes: #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>
  • Loading branch information
cjihrig committed Feb 26, 2019
1 parent 4900863 commit 907941d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-http-client-timeout-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 907941d

Please sign in to comment.