http: support old private properties and function

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Brian White 2017-03-05 21:15:15 -05:00
Родитель 940b5303be
Коммит b377034359
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 606D7358F94DA209
1 изменённых файлов: 69 добавлений и 0 удалений

Просмотреть файл

@ -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;