Skip to content

Commit

Permalink
http: support old private properties and function
Browse files Browse the repository at this point in the history
PR-URL: nodejs#10941
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
mscdex authored and jungx098 committed Mar 21, 2017
1 parent 9a1982e commit b088f5c
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,75 @@ function OutgoingMessage() {
util.inherits(OutgoingMessage, Stream);


Object.defineProperty(OutgoingMessage.prototype, '_headers', {
get: function() {
return this.getHeaders();
},
set: function(val) {
if (val == null) {
this[outHeadersKey] = null;
} else if (typeof val === 'object') {
const headers = this[outHeadersKey] = {};
const keys = Object.keys(val);
for (var i = 0; i < keys.length; ++i) {
const name = keys[i];
headers[name.toLowerCase()] = [name, val[name]];
}
}
}
});

Object.defineProperty(OutgoingMessage.prototype, '_headerNames', {
get: function() {
const headers = this[outHeadersKey];
if (headers) {
const out = new StorageObject();
const keys = Object.keys(headers);
for (var i = 0; i < keys.length; ++i) {
const key = keys[i];
const val = headers[key][0];
out[key] = val;
}
return out;
} else {
return headers;
}
},
set: function(val) {
if (typeof val === 'object' && val !== null) {
const headers = this[outHeadersKey];
if (!headers)
return;
const keys = Object.keys(val);
for (var i = 0; i < keys.length; ++i) {
const header = headers[keys[i]];
if (header)
header[0] = val[keys[i]];
}
}
}
});


OutgoingMessage.prototype._renderHeaders = function _renderHeaders() {
if (this._header) {
throw new Error('Can\'t render headers after they are sent to the client');
}

var headersMap = this[outHeadersKey];
if (!headersMap) return {};

var headers = {};
var keys = Object.keys(headersMap);

for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i];
headers[headersMap[key][0]] = headersMap[key][1];
}
return headers;
};


exports.OutgoingMessage = OutgoingMessage;


Expand Down

0 comments on commit b088f5c

Please sign in to comment.