diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index f40cf923f9b377..066edc58626eec 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -165,9 +165,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, '_headers', { this[kOutHeaders] = null; } else if (typeof val === 'object') { const headers = this[kOutHeaders] = ObjectCreate(null); - const keys = ObjectKeys(val); - for (var i = 0; i < keys.length; ++i) { - const name = keys[i]; + for (name of ObjectKeys(val)) { headers[name.toLowerCase()] = [name, val[name]]; } } @@ -188,9 +186,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, '_headerNames', { const headers = this[kOutHeaders]; if (headers !== null) { const out = ObjectCreate(null); - const keys = ObjectKeys(headers); - for (var i = 0; i < keys.length; ++i) { - const key = keys[i]; + for (key of ObjectKeys(headers)) { const val = headers[key][0]; out[key] = val; } @@ -203,11 +199,10 @@ ObjectDefineProperty(OutgoingMessage.prototype, '_headerNames', { const headers = this[kOutHeaders]; if (!headers) return; - const keys = ObjectKeys(val); - for (var i = 0; i < keys.length; ++i) { - const header = headers[keys[i]]; + for (key of ObjectKeys(val)) { + const header = headers[key]; if (header) - header[0] = val[keys[i]]; + header[0] = val[key]; } } }, 'OutgoingMessage.prototype._headerNames is deprecated', 'DEP0066') @@ -223,9 +218,7 @@ OutgoingMessage.prototype._renderHeaders = function _renderHeaders() { const headers = {}; if (headersMap !== null) { - const keys = ObjectKeys(headersMap); - for (var i = 0, l = keys.length; i < l; i++) { - const key = keys[i]; + for (key of ObjectKeys(headersMap)) { headers[headersMap[key][0]] = headersMap[key][1]; } } @@ -458,8 +451,8 @@ function processHeader(self, state, key, value, validate) { validateHeaderName(key); if (ArrayIsArray(value)) { if (value.length < 2 || !isCookieField(key)) { - for (var i = 0; i < value.length; i++) - storeHeader(self, state, key, value[i], validate); + for (keyValue of value) + storeHeader(self, state, key, keyValue, validate); return; } value = value.join('; '); @@ -558,9 +551,7 @@ OutgoingMessage.prototype.getHeaders = function getHeaders() { const headers = this[kOutHeaders]; const ret = ObjectCreate(null); if (headers) { - const keys = ObjectKeys(headers); - for (var i = 0; i < keys.length; ++i) { - const key = keys[i]; + for (key of ObjectKeys(headers)) { const val = headers[key][1]; ret[key] = val; } @@ -697,11 +688,9 @@ function connectionCorkNT(conn) { OutgoingMessage.prototype.addTrailers = function addTrailers(headers) { this._trailer = ''; - const keys = ObjectKeys(headers); const isArray = ArrayIsArray(headers); var field, value; - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i]; + for (key of ObjectKeys(headers)) { if (isArray) { field = headers[key][0]; value = headers[key][1]; @@ -847,15 +836,13 @@ OutgoingMessage.prototype._flushOutput = function _flushOutput(socket) { socket.cork(); } - const outputLength = this.outputData.length; - if (outputLength <= 0) + if (this.outputData.length <= 0) return undefined; - const outputData = this.outputData; socket.cork(); let ret; - for (var i = 0; i < outputLength; i++) { - const { data, encoding, callback } = outputData[i]; + for (outputDataItem of this.outputData) { + const { data, encoding, callback } = outputDataItem; ret = socket.write(data, encoding, callback); } socket.uncork();