Skip to content

Commit

Permalink
http: for of in lib/_http_outgoing.js
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Dec 14, 2019
1 parent 3ba1da2 commit b4b4d3d
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
}
Expand All @@ -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;
}
Expand All @@ -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')
Expand All @@ -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];
}
}
Expand Down Expand Up @@ -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('; ');
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b4b4d3d

Please sign in to comment.