From 98963f2a0e1e6088a5f745ff37a5b096e157f322 Mon Sep 17 00:00:00 2001 From: telenord Date: Wed, 6 Nov 2019 13:22:01 +0300 Subject: [PATCH] http: revise _http_server.js * replace var with const * eliminate unnecessary bytesParsed variable http: remove bytesParsed var PR-URL: https://github.com/nodejs/node/pull/30279 Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat Reviewed-By: Yorkie Liu Reviewed-By: Gireesh Punathil Reviewed-By: James M Snell --- lib/_http_server.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index 58f0973ddd8b02..5d8b02ef1234c8 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -253,13 +253,13 @@ function writeHead(statusCode, reason, obj) { } this.statusCode = statusCode; - var headers; + let headers; if (this[kOutHeaders]) { // Slow-case: when progressive API and header fields are passed. - var k; + let k; if (obj) { - var keys = Object.keys(obj); - for (var i = 0; i < keys.length; i++) { + const keys = Object.keys(obj); + for (let i = 0; i < keys.length; i++) { k = keys[i]; if (k) this.setHeader(k, obj[k]); } @@ -487,7 +487,7 @@ function socketOnClose(socket, state) { function abortIncoming(incoming) { while (incoming.length) { - var req = incoming.shift(); + const req = incoming.shift(); req.aborted = true; req.emit('aborted'); req.emit('close'); @@ -577,8 +577,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { socketOnError.call(socket, ret); } else if (parser.incoming && parser.incoming.upgrade) { // Upgrade or CONNECT - var bytesParsed = ret; - var req = parser.incoming; + const req = parser.incoming; debug('SERVER upgrade or connect', req.method); if (!d) @@ -594,10 +593,10 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { freeParser(parser, req, socket); parser = null; - var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade'; + const eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade'; if (eventName === 'upgrade' || server.listenerCount(eventName) > 0) { debug('SERVER have listener for %s', eventName); - var bodyHead = d.slice(bytesParsed, d.length); + const bodyHead = d.slice(ret, d.length); socket.readableFlowing = null; server.emit(eventName, req, socket, bodyHead); @@ -659,7 +658,7 @@ function resOnFinish(req, res, socket, state, server) { } } else { // Start sending the next message - var m = state.outgoing.shift(); + const m = state.outgoing.shift(); if (m) { m.assignSocket(socket); } @@ -696,7 +695,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { // so that we don't become overwhelmed by a flood of // pipelined requests that may never be resolved. if (!socket._paused) { - var ws = socket._writableState; + const ws = socket._writableState; if (ws.needDrain || state.outgoingData >= socket.writableHighWaterMark) { socket._paused = true; // We also need to pause the parser, but don't do that until after