Skip to content

Commit 6e7f9fb

Browse files
deokjinkimRafaelGSS
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 <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e85f766 commit 6e7f9fb

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
NumberParseInt,
3534
ObjectKeys,
3635
ObjectSetPrototypeOf,
@@ -50,11 +49,6 @@ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
5049
});
5150
const { AsyncResource } = require('async_hooks');
5251
const { async_id_symbol } = require('internal/async_hooks').symbols;
53-
const {
54-
codes: {
55-
ERR_OUT_OF_RANGE,
56-
},
57-
} = require('internal/errors');
5852
const {
5953
kEmptyObject,
6054
once,
@@ -124,10 +118,7 @@ function Agent(options) {
124118
validateOneOf(this.scheduling, 'scheduling', ['fifo', 'lifo']);
125119

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

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)