@ -13,14 +13,6 @@ const checkInvalidHeaderChar = common._checkInvalidHeaderChar;
const CRLF = common . CRLF ;
const CRLF = common . CRLF ;
const debug = common . debug ;
const debug = common . debug ;
const automaticHeaders = {
connection : true ,
'content-length' : true ,
'transfer-encoding' : true ,
date : true
} ;
var RE_FIELDS = new RegExp ( '^(?:Connection|Transfer-Encoding|Content-Length|' +
var RE_FIELDS = new RegExp ( '^(?:Connection|Transfer-Encoding|Content-Length|' +
'Date|Expect|Trailer|Upgrade)$' , 'i' ) ;
'Date|Expect|Trailer|Upgrade)$' , 'i' ) ;
var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig ;
var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig ;
@ -64,7 +56,9 @@ function OutgoingMessage() {
this . shouldKeepAlive = true ;
this . shouldKeepAlive = true ;
this . useChunkedEncodingByDefault = true ;
this . useChunkedEncodingByDefault = true ;
this . sendDate = false ;
this . sendDate = false ;
this . _ removedHeader = { } ;
this . _ removedConnection = false ;
this . _ removedContLen = false ;
this . _ removedTE = false ;
this . _ contentLength = null ;
this . _ contentLength = null ;
this . _ hasBody = true ;
this . _ hasBody = true ;
@ -279,7 +273,7 @@ function _storeHeader(firstLine, headers) {
}
}
// keep-alive logic
// keep-alive logic
if ( this . _ removedHeader . c onnection ) {
if ( this . _ removedC onnection ) {
this . _ last = true ;
this . _ last = true ;
this . shouldKeepAlive = false ;
this . shouldKeepAlive = false ;
} else if ( ! state . connection ) {
} else if ( ! state . connection ) {
@ -300,11 +294,11 @@ function _storeHeader(firstLine, headers) {
} else if ( ! this . useChunkedEncodingByDefault ) {
} else if ( ! this . useChunkedEncodingByDefault ) {
this . _ last = true ;
this . _ last = true ;
} else {
} else {
! this . _ removedHeader [ 'content-length' ] &&
if ( ! state . trailer &&
if ( ! state . trailer &&
! this . _ removedContLen &&
typeof this . _ contentLength === 'number' ) {
typeof this . _ contentLength === 'number' ) {
} else if ( ! this . _ removedHeader [ 'transfer-encoding' ] ) {
state . header += 'Content-Length: ' + this . _ contentLength + CRLF ;
state . header += 'Content-Length: ' + this . _ contentLength + CRLF ;
} else if ( ! this . _ removedTE ) {
state . header += 'Transfer-Encoding: chunked\r\n' ;
state . header += 'Transfer-Encoding: chunked\r\n' ;
this . chunkedEncoding = true ;
this . chunkedEncoding = true ;
} else {
} else {
@ -405,8 +399,20 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
const key = name . toLowerCase ( ) ;
const key = name . toLowerCase ( ) ;
this . _ headers [ key ] = [ name , value ] ;
this . _ headers [ key ] = [ name , value ] ;
if ( automaticHeaders [ key ] )
switch ( key . length ) {
this . _ removedHeader [ key ] = false ;
case 10 :
if ( key === 'connection' )
this . _ removedConnection = false ;
break ;
case 14 :
if ( key === 'content-length' )
this . _ removedContLen = false ;
break ;
case 17 :
if ( key === 'transfer-encoding' )
this . _ removedTE = false ;
break ;
}
} ;
} ;
@ -435,10 +441,24 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
var key = name . toLowerCase ( ) ;
var key = name . toLowerCase ( ) ;
switch ( key . length ) {
case 10 :
if ( key === 'connection' )
this . _ removedConnection = true ;
break ;
case 14 :
if ( key === 'content-length' )
this . _ removedContLen = true ;
break ;
case 17 :
if ( key === 'transfer-encoding' )
this . _ removedTE = true ;
break ;
case 4 :
if ( key === 'date' )
if ( key === 'date' )
this . sendDate = false ;
this . sendDate = false ;
else if ( automaticHeaders [ key ] )
break ;
this . _ removedHeader [ key ] = true ;
}
if ( this . _ headers ) {
if ( this . _ headers ) {
delete this . _ headers [ key ] ;
delete this . _ headers [ key ] ;