From a0a61b81a52a2bb71569fe0393553ce30cd5cdac Mon Sep 17 00:00:00 2001 From: Yash Ladha Date: Thu, 4 Jun 2020 23:35:27 +0530 Subject: [PATCH] http: used already defined validator for boolean check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We already importing the validator for integer check. So leveraging the boolean check validator to remove already defined logic in the code and thus making it DRY. PR-URL: https://github.com/nodejs/node/pull/33731 Reviewed-By: James M Snell Reviewed-By: Denys Otrishko Reviewed-By: Colin Ihrig Reviewed-By: Juan José Arboleda Reviewed-By: Trivikram Kamat --- lib/_http_server.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index c8b27dcd42cb5b..680fadba715f07 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -62,7 +62,10 @@ const { ERR_INVALID_ARG_TYPE, ERR_INVALID_CHAR } = require('internal/errors').codes; -const { validateInteger } = require('internal/validators'); +const { + validateInteger, + validateBoolean +} = require('internal/validators'); const Buffer = require('buffer').Buffer; const { DTRACE_HTTP_SERVER_REQUEST, @@ -336,11 +339,8 @@ function Server(options, requestListener) { this.maxHeaderSize = maxHeaderSize; const insecureHTTPParser = options.insecureHTTPParser; - if (insecureHTTPParser !== undefined && - typeof insecureHTTPParser !== 'boolean') { - throw new ERR_INVALID_ARG_TYPE( - 'options.insecureHTTPParser', 'boolean', insecureHTTPParser); - } + if (insecureHTTPParser !== undefined) + validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser'); this.insecureHTTPParser = insecureHTTPParser; net.Server.call(this, { allowHalfOpen: true }); @@ -372,9 +372,7 @@ Server.prototype.setTimeout = function setTimeout(msecs, callback) { return this; }; -Server.prototype[EE.captureRejectionSymbol] = function( - err, event, ...args) { - +Server.prototype[EE.captureRejectionSymbol] = function(err, event, ...args) { switch (event) { case 'request': const [ , res] = args;