Skip to content

Commit 3d1dd96

Browse files
deokjinkimjuanarbol
authored andcommitted
http: refactor to use min of validateNumber for maxTotalSockets
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>
1 parent 53ecd20 commit 3d1dd96

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

lib/_http_agent.js

+1-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const {
3030
ArrayPrototypeSome,
3131
ArrayPrototypeSplice,
3232
FunctionPrototypeCall,
33-
NumberIsNaN,
3433
ObjectCreate,
3534
ObjectKeys,
3635
ObjectSetPrototypeOf,
@@ -49,11 +48,6 @@ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
4948
});
5049
const { AsyncResource } = require('async_hooks');
5150
const { async_id_symbol } = require('internal/async_hooks').symbols;
52-
const {
53-
codes: {
54-
ERR_OUT_OF_RANGE,
55-
},
56-
} = require('internal/errors');
5751
const {
5852
kEmptyObject,
5953
once,
@@ -123,10 +117,7 @@ function Agent(options) {
123117
validateOneOf(this.scheduling, 'scheduling', ['fifo', 'lifo']);
124118

125119
if (this.maxTotalSockets !== undefined) {
126-
validateNumber(this.maxTotalSockets, 'maxTotalSockets');
127-
if (this.maxTotalSockets <= 0 || NumberIsNaN(this.maxTotalSockets))
128-
throw new ERR_OUT_OF_RANGE('maxTotalSockets', '> 0',
129-
this.maxTotalSockets);
120+
validateNumber(this.maxTotalSockets, 'maxTotalSockets', 1);
130121
} else {
131122
this.maxTotalSockets = Infinity;
132123
}

test/parallel/test-http-agent-maxtotalsockets.js

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ assert.throws(() => new http.Agent({
2020
}), {
2121
code: 'ERR_OUT_OF_RANGE',
2222
name: 'RangeError',
23-
message: 'The value of "maxTotalSockets" is out of range. ' +
24-
`It must be > 0. Received ${item}`,
2523
});
2624
});
2725

0 commit comments

Comments
 (0)