Permalink
Browse files

http: support old private properties and function

PR-URL: #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 committed Mar 6, 2017
1 parent 940b530 commit b377034359aa07f2ba83a5a0c9f859418cb80e39
Showing with 69 additions and 0 deletions.
  1. +69 −0 lib/_http_outgoing.js
View
@@ -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;

0 comments on commit b377034

Please sign in to comment.