Skip to content

Commit b377034

Browse files
committed
http: support old private properties and function
PR-URL: #10941 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 940b530 commit b377034

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

‎lib/_http_outgoing.js‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,75 @@ function OutgoingMessage(){
8383
util.inherits(OutgoingMessage,Stream);
8484

8585

86+
Object.defineProperty(OutgoingMessage.prototype,'_headers',{
87+
get: function(){
88+
returnthis.getHeaders();
89+
},
90+
set: function(val){
91+
if(val==null){
92+
this[outHeadersKey]=null;
93+
}elseif(typeofval==='object'){
94+
constheaders=this[outHeadersKey]={};
95+
constkeys=Object.keys(val);
96+
for(vari=0;i<keys.length;++i){
97+
constname=keys[i];
98+
headers[name.toLowerCase()]=[name,val[name]];
99+
}
100+
}
101+
}
102+
});
103+
104+
Object.defineProperty(OutgoingMessage.prototype,'_headerNames',{
105+
get: function(){
106+
constheaders=this[outHeadersKey];
107+
if(headers){
108+
constout=newStorageObject();
109+
constkeys=Object.keys(headers);
110+
for(vari=0;i<keys.length;++i){
111+
constkey=keys[i];
112+
constval=headers[key][0];
113+
out[key]=val;
114+
}
115+
returnout;
116+
}else{
117+
returnheaders;
118+
}
119+
},
120+
set: function(val){
121+
if(typeofval==='object'&&val!==null){
122+
constheaders=this[outHeadersKey];
123+
if(!headers)
124+
return;
125+
constkeys=Object.keys(val);
126+
for(vari=0;i<keys.length;++i){
127+
constheader=headers[keys[i]];
128+
if(header)
129+
header[0]=val[keys[i]];
130+
}
131+
}
132+
}
133+
});
134+
135+
136+
OutgoingMessage.prototype._renderHeaders=function_renderHeaders(){
137+
if(this._header){
138+
thrownewError('Can\'t render headers after they are sent to the client');
139+
}
140+
141+
varheadersMap=this[outHeadersKey];
142+
if(!headersMap)return{};
143+
144+
varheaders={};
145+
varkeys=Object.keys(headersMap);
146+
147+
for(vari=0,l=keys.length;i<l;i++){
148+
varkey=keys[i];
149+
headers[headersMap[key][0]]=headersMap[key][1];
150+
}
151+
returnheaders;
152+
};
153+
154+
86155
exports.OutgoingMessage=OutgoingMessage;
87156

88157

0 commit comments

Comments
(0)