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:
Родитель
940b5303be
Коммит
b377034359
|
@ -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;
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче