From 3d1dd96c4fe2a1219156c63a8689015a66bb7414 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Fri, 13 Jan 2023 23:39:54 +0900 Subject: [PATCH] http: refactor to use min of validateNumber for maxTotalSockets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove duplicate implementation by using min of validateNumber. PR-URL: https://github.com/nodejs/node/pull/46115 Reviewed-By: Paolo Insogna Reviewed-By: Matteo Collina Reviewed-By: Tobias Nießen Reviewed-By: James M Snell --- lib/_http_agent.js | 11 +---------- test/parallel/test-http-agent-maxtotalsockets.js | 2 -- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 791a43c8d5d029..774c5824658434 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -30,7 +30,6 @@ const { ArrayPrototypeSome, ArrayPrototypeSplice, FunctionPrototypeCall, - NumberIsNaN, ObjectCreate, ObjectKeys, ObjectSetPrototypeOf, @@ -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, @@ -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; } diff --git a/test/parallel/test-http-agent-maxtotalsockets.js b/test/parallel/test-http-agent-maxtotalsockets.js index c44c8db627d330..fce1bf8de83144 100644 --- a/test/parallel/test-http-agent-maxtotalsockets.js +++ b/test/parallel/test-http-agent-maxtotalsockets.js @@ -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}`, }); });