From 7c8843ccd792616b3bc8f8b4e09b04038aa24a78 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 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. --- 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 f11c74ff7c4303..e23db380d8c39b 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -67,7 +67,10 @@ const { ERR_INVALID_ARG_TYPE, ERR_INVALID_CHAR } = codes; -const { validateInteger } = require('internal/validators'); +const { + validateInteger, + validateBoolean +} = require('internal/validators'); const Buffer = require('buffer').Buffer; const { DTRACE_HTTP_SERVER_REQUEST, @@ -344,11 +347,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 }); @@ -380,9 +380,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;