Skip to content

Commit 940b530

Browse files
committed
http: use Symbol for outgoing headers
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 86996c5 commit 940b530

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

‎lib/_http_client.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const OutgoingMessage = require('_http_outgoing').OutgoingMessage;
1414
constAgent=require('_http_agent');
1515
constBuffer=require('buffer').Buffer;
1616
consturlToOptions=require('internal/url').urlToOptions;
17+
constoutHeadersKey=require('internal/http').outHeadersKey;
1718

1819
// The actual list of disallowed characters in regexp form is more like:
1920
// /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/
@@ -182,7 +183,7 @@ function ClientRequest(options, cb){
182183
'client');
183184
}
184185
self._storeHeader(self.method+' '+self.path+' HTTP/1.1\r\n',
185-
self._headers);
186+
self[outHeadersKey]);
186187
}
187188

188189
this._ended=false;
@@ -278,7 +279,7 @@ ClientRequest.prototype._implicitHeader = function _implicitHeader(){
278279
thrownewError('Can\'t render headers after they are sent to the client');
279280
}
280281
this._storeHeader(this.method+' '+this.path+' HTTP/1.1\r\n',
281-
this._headers);
282+
this[outHeadersKey]);
282283
};
283284

284285
ClientRequest.prototype.abort=functionabort(){

‎lib/_http_outgoing.js‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const Buffer = require('buffer').Buffer;
99
constcommon=require('_http_common');
1010
constcheckIsHttpToken=common._checkIsHttpToken;
1111
constcheckInvalidHeaderChar=common._checkInvalidHeaderChar;
12+
constoutHeadersKey=require('internal/http').outHeadersKey;
13+
constStorageObject=require('internal/querystring').StorageObject;
1214

1315
constCRLF=common.CRLF;
1416
constdebug=common.debug;
@@ -74,7 +76,7 @@ function OutgoingMessage(){
7476
this.socket=null;
7577
this.connection=null;
7678
this._header=null;
77-
this._headers=null;
79+
this[outHeadersKey]=null;
7880

7981
this._onPendingData=null;
8082
}
@@ -201,7 +203,7 @@ function _storeHeader(firstLine, headers){
201203
varvalue;
202204
vari;
203205
varj;
204-
if(headers===this._headers){
206+
if(headers===this[outHeadersKey]){
205207
for(keyinheaders){
206208
varentry=headers[key];
207209
field=entry[0];
@@ -393,11 +395,11 @@ function validateHeader(msg, name, value){
393395
OutgoingMessage.prototype.setHeader=functionsetHeader(name,value){
394396
validateHeader(this,name,value);
395397

396-
if(!this._headers)
397-
this._headers={};
398+
if(!this[outHeadersKey])
399+
this[outHeadersKey]={};
398400

399401
constkey=name.toLowerCase();
400-
this._headers[key]=[name,value];
402+
this[outHeadersKey][key]=[name,value];
401403

402404
switch(key.length){
403405
case10:
@@ -421,9 +423,9 @@ OutgoingMessage.prototype.getHeader = function getHeader(name){
421423
thrownewTypeError('"name" argument must be a string');
422424
}
423425

424-
if(!this._headers)return;
426+
if(!this[outHeadersKey])return;
425427

426-
varentry=this._headers[name.toLowerCase()];
428+
varentry=this[outHeadersKey][name.toLowerCase()];
427429
if(!entry)
428430
return;
429431
returnentry[1];
@@ -432,13 +434,13 @@ OutgoingMessage.prototype.getHeader = function getHeader(name){
432434

433435
// Returns an array of the names of the current outgoing headers.
434436
OutgoingMessage.prototype.getHeaderNames=functiongetHeaderNames(){
435-
return(this._headers ? Object.keys(this._headers) : []);
437+
return(this[outHeadersKey] ? Object.keys(this[outHeadersKey]) : []);
436438
};
437439

438440

439441
// Returns a shallow copy of the current outgoing headers.
440442
OutgoingMessage.prototype.getHeaders=functiongetHeaders(){
441-
constheaders=this._headers;
443+
constheaders=this[outHeadersKey];
442444
constret=newOutgoingHeaders();
443445
if(headers){
444446
constkeys=Object.keys(headers);
@@ -457,7 +459,7 @@ OutgoingMessage.prototype.hasHeader = function hasHeader(name){
457459
thrownewTypeError('"name" argument must be a string');
458460
}
459461

460-
return!!(this._headers&&this._headers[name.toLowerCase()]);
462+
return!!(this[outHeadersKey]&&this[outHeadersKey][name.toLowerCase()]);
461463
};
462464

463465

@@ -491,8 +493,8 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name){
491493
break;
492494
}
493495

494-
if(this._headers){
495-
deletethis._headers[key];
496+
if(this[outHeadersKey]){
497+
deletethis[outHeadersKey][key];
496498
}
497499
};
498500

‎lib/_http_server.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const continueExpression = common.continueExpression;
1313
constchunkExpression=common.chunkExpression;
1414
consthttpSocketSetup=common.httpSocketSetup;
1515
constOutgoingMessage=require('_http_outgoing').OutgoingMessage;
16+
constoutHeadersKey=require('internal/http').outHeadersKey;
1617

1718
constSTATUS_CODES=exports.STATUS_CODES={
1819
100: 'Continue',
@@ -179,7 +180,7 @@ function writeHead(statusCode, reason, obj){
179180
this.statusCode=statusCode;
180181

181182
varheaders;
182-
if(this._headers){
183+
if(this[outHeadersKey]){
183184
// Slow-case: when progressive API and header fields are passed.
184185
vark;
185186
if(obj){
@@ -196,7 +197,7 @@ function writeHead(statusCode, reason, obj){
196197
}
197198
}
198199
// only progressive api is used
199-
headers=this._headers;
200+
headers=this[outHeadersKey];
200201
}else{
201202
// only writeHead() called
202203
headers=obj;

‎lib/internal/http.js‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports={
4+
outHeadersKey: Symbol('outHeadersKey')
5+
};

‎node.gyp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
'lib/internal/errors.js',
8686
'lib/internal/freelist.js',
8787
'lib/internal/fs.js',
88+
'lib/internal/http.js',
8889
'lib/internal/linkedlist.js',
8990
'lib/internal/net.js',
9091
'lib/internal/module.js',

0 commit comments

Comments
(0)