Skip to content

Commit db788cb

Browse files
committed
http: refactor to use min of validateNumber for maxTotalSockets
Remove duplicate implementation by using min of validateNumber.
1 parent 0593b69 commit db788cb

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

lib/_http_agent.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const {
3030
ArrayPrototypeSome,
3131
ArrayPrototypeSplice,
3232
FunctionPrototypeCall,
33-
NumberIsNaN,
3433
NumberParseInt,
3534
ObjectCreate,
3635
ObjectKeys,
@@ -51,11 +50,6 @@ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
5150
});
5251
const { AsyncResource } = require('async_hooks');
5352
const { async_id_symbol } = require('internal/async_hooks').symbols;
54-
const {
55-
codes: {
56-
ERR_OUT_OF_RANGE,
57-
},
58-
} = require('internal/errors');
5953
const {
6054
kEmptyObject,
6155
once,
@@ -125,10 +119,7 @@ function Agent(options) {
125119
validateOneOf(this.scheduling, 'scheduling', ['fifo', 'lifo']);
126120

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

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

Lines changed: 0 additions & 2 deletions
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)