From bf7a52b7648ea85a021b4f104bbed5988697ecae Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Sun, 3 Mar 2019 12:24:54 +0800 Subject: [PATCH] http: improve for-loop readability in _http_outgoing.js PR-URL: https://github.com/nodejs/node/pull/26408 Reviewed-By: Ruben Bridgewater Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca --- lib/_http_outgoing.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 671a1477d8be1a..a8e970d2d42103 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -295,21 +295,21 @@ function _storeHeader(firstLine, headers) { header: firstLine }; - var key; - if (headers === this[outHeadersKey]) { - for (key in headers) { - const entry = headers[key]; - processHeader(this, state, entry[0], entry[1], false); - } - } else if (Array.isArray(headers)) { - for (var i = 0; i < headers.length; i++) { - const entry = headers[i]; - processHeader(this, state, entry[0], entry[1], true); - } - } else if (headers) { - for (key in headers) { - if (hasOwnProperty(headers, key)) { - processHeader(this, state, key, headers[key], true); + if (headers) { + if (headers === this[outHeadersKey]) { + for (const key in headers) { + const entry = headers[key]; + processHeader(this, state, entry[0], entry[1], false); + } + } else if (Array.isArray(headers)) { + for (const entry of headers) { + processHeader(this, state, entry[0], entry[1], true); + } + } else { + for (const key in headers) { + if (hasOwnProperty(headers, key)) { + processHeader(this, state, key, headers[key], true); + } } } }