Skip to content

Commit

Permalink
http: refactor to use min of validateNumber for maxTotalSockets
Browse files Browse the repository at this point in the history
Remove duplicate implementation by using min of validateNumber.

PR-URL: #46115
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
deokjinkim authored and juanarbol committed Jan 31, 2023
1 parent 53ecd20 commit 3d1dd96
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
11 changes: 1 addition & 10 deletions lib/_http_agent.js
Expand Up @@ -30,7 +30,6 @@ const {
ArrayPrototypeSome,
ArrayPrototypeSplice,
FunctionPrototypeCall,
NumberIsNaN,
ObjectCreate,
ObjectKeys,
ObjectSetPrototypeOf,
Expand All @@ -49,11 +48,6 @@ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
});
const { AsyncResource } = require('async_hooks');
const { async_id_symbol } = require('internal/async_hooks').symbols;
const {
codes: {
ERR_OUT_OF_RANGE,
},
} = require('internal/errors');
const {
kEmptyObject,
once,
Expand Down Expand Up @@ -123,10 +117,7 @@ function Agent(options) {
validateOneOf(this.scheduling, 'scheduling', ['fifo', 'lifo']);

if (this.maxTotalSockets !== undefined) {
validateNumber(this.maxTotalSockets, 'maxTotalSockets');
if (this.maxTotalSockets <= 0 || NumberIsNaN(this.maxTotalSockets))
throw new ERR_OUT_OF_RANGE('maxTotalSockets', '> 0',
this.maxTotalSockets);
validateNumber(this.maxTotalSockets, 'maxTotalSockets', 1);
} else {
this.maxTotalSockets = Infinity;
}
Expand Down
2 changes: 0 additions & 2 deletions test/parallel/test-http-agent-maxtotalsockets.js
Expand Up @@ -20,8 +20,6 @@ assert.throws(() => new http.Agent({
}), {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
message: 'The value of "maxTotalSockets" is out of range. ' +
`It must be > 0. Received ${item}`,
});
});

Expand Down

0 comments on commit 3d1dd96

Please sign in to comment.