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 RafaelGSS committed Jan 20, 2023
1 parent e85f766 commit 6e7f9fb
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const {
ArrayPrototypeSome,
ArrayPrototypeSplice,
FunctionPrototypeCall,
NumberIsNaN,
NumberParseInt,
ObjectKeys,
ObjectSetPrototypeOf,
Expand All @@ -50,11 +49,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 @@ -124,10 +118,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
Original file line number Diff line number Diff line change
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 6e7f9fb

Please sign in to comment.