@@ -13,14 +13,6 @@ const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
13
13
const CRLF = common . CRLF ;
14
14
const debug = common . debug ;
15
15
16
-
17
- const automaticHeaders = {
18
- connection : true ,
19
- 'content-length' : true ,
20
- 'transfer-encoding' : true ,
21
- date : true
22
- } ;
23
-
24
16
var RE_FIELDS = new RegExp ( '^(?:Connection|Transfer-Encoding|Content-Length|' +
25
17
'Date|Expect|Trailer|Upgrade)$' , 'i' ) ;
26
18
var RE_CONN_VALUES = / (?: ^ | \W ) c l o s e | u p g r a d e (?: $ | \W ) / ig;
@@ -64,7 +56,9 @@ function OutgoingMessage() {
64
56
this . shouldKeepAlive = true ;
65
57
this . useChunkedEncodingByDefault = true ;
66
58
this . sendDate = false ;
67
- this . _removedHeader = { } ;
59
+ this . _removedConnection = false ;
60
+ this . _removedContLen = false ;
61
+ this . _removedTE = false ;
68
62
69
63
this . _contentLength = null ;
70
64
this . _hasBody = true ;
@@ -279,7 +273,7 @@ function _storeHeader(firstLine, headers) {
279
273
}
280
274
281
275
// keep-alive logic
282
- if ( this . _removedHeader . connection ) {
276
+ if ( this . _removedConnection ) {
283
277
this . _last = true ;
284
278
this . shouldKeepAlive = false ;
285
279
} else if ( ! state . connection ) {
@@ -300,11 +294,11 @@ function _storeHeader(firstLine, headers) {
300
294
} else if ( ! this . useChunkedEncodingByDefault ) {
301
295
this . _last = true ;
302
296
} else {
303
- ! this . _removedHeader [ 'content-length' ] &&
304
297
if ( ! state . trailer &&
298
+ ! this . _removedContLen &&
305
299
typeof this . _contentLength === 'number' ) {
306
- } else if ( ! this . _removedHeader [ 'transfer-encoding' ] ) {
307
300
state . header += 'Content-Length: ' + this . _contentLength + CRLF ;
301
+ } else if ( ! this . _removedTE ) {
308
302
state . header += 'Transfer-Encoding: chunked\r\n' ;
309
303
this . chunkedEncoding = true ;
310
304
} else {
@@ -405,8 +399,20 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
405
399
const key = name . toLowerCase ( ) ;
406
400
this . _headers [ key ] = [ name , value ] ;
407
401
408
- if ( automaticHeaders [ key ] )
409
- this . _removedHeader [ key ] = false ;
402
+ switch ( key . length ) {
403
+ case 10 :
404
+ if ( key === 'connection' )
405
+ this . _removedConnection = false ;
406
+ break ;
407
+ case 14 :
408
+ if ( key === 'content-length' )
409
+ this . _removedContLen = false ;
410
+ break ;
411
+ case 17 :
412
+ if ( key === 'transfer-encoding' )
413
+ this . _removedTE = false ;
414
+ break ;
415
+ }
410
416
} ;
411
417
412
418
@@ -435,10 +441,24 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
435
441
436
442
var key = name . toLowerCase ( ) ;
437
443
438
- if ( key === 'date' )
439
- this . sendDate = false ;
440
- else if ( automaticHeaders [ key ] )
441
- this . _removedHeader [ key ] = true ;
444
+ switch ( key . length ) {
445
+ case 10 :
446
+ if ( key === 'connection' )
447
+ this . _removedConnection = true ;
448
+ break ;
449
+ case 14 :
450
+ if ( key === 'content-length' )
451
+ this . _removedContLen = true ;
452
+ break ;
453
+ case 17 :
454
+ if ( key === 'transfer-encoding' )
455
+ this . _removedTE = true ;
456
+ break ;
457
+ case 4 :
458
+ if ( key === 'date' )
459
+ this . sendDate = false ;
460
+ break ;
461
+ }
442
462
443
463
if ( this . _headers ) {
444
464
delete this . _headers [ key ] ;
0 commit comments