@@ -9,16 +9,18 @@ const Buffer = require('buffer').Buffer;
99const common = require ( '_http_common' ) ;
1010
1111const CRLF = common . CRLF ;
12- const chunkExpression = common . chunkExpression ;
12+ const trfrEncChunkExpression = common . chunkExpression ;
1313const debug = common . debug ;
1414
15- const connectionExpression = / ^ C o n n e c t i o n $ / i;
15+ const upgradeExpression = / ^ U p g r a d e $ / i;
1616const transferEncodingExpression = / ^ T r a n s f e r - E n c o d i n g $ / i;
17- const closeExpression = / c l o s e / i;
1817const contentLengthExpression = / ^ C o n t e n t - L e n g t h $ / i;
1918const dateExpression = / ^ D a t e $ / i;
2019const expectExpression = / ^ E x p e c t $ / i;
2120const trailerExpression = / ^ T r a i l e r $ / i;
21+ const connectionExpression = / ^ C o n n e c t i o n $ / i;
22+ const connCloseExpression = / ( ^ | \W ) c l o s e ( \W | $ ) / i;
23+ const connUpgradeExpression = / ( ^ | \W ) u p g r a d e ( \W | $ ) / i;
2224
2325const automaticHeaders = {
2426 connection : true ,
@@ -61,6 +63,7 @@ function OutgoingMessage() {
6163 this . writable = true ;
6264
6365 this . _last = false ;
66+ this . upgrading = false ;
6467 this . chunkedEncoding = false ;
6568 this . shouldKeepAlive = true ;
6669 this . useChunkedEncodingByDefault = true ;
@@ -192,11 +195,13 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
192195 // in the case of response it is: 'HTTP/1.1 200 OK\r\n'
193196 var state = {
194197 sentConnectionHeader : false ,
198+ sentConnectionUpgrade : false ,
195199 sentContentLengthHeader : false ,
196200 sentTransferEncodingHeader : false ,
197201 sentDateHeader : false ,
198202 sentExpect : false ,
199203 sentTrailer : false ,
204+ sentUpgrade : false ,
200205 messageHeader : firstLine
201206 } ;
202207
@@ -225,6 +230,10 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
225230 }
226231 }
227232
233+ // Are we upgrading the connection?
234+ if ( state . sentConnectionUpgrade && state . sentUpgrade )
235+ this . upgrading = true ;
236+
228237 // Date header
229238 if ( this . sendDate === true && state . sentDateHeader === false ) {
230239 state . messageHeader += 'Date: ' + utcDate ( ) + CRLF ;
@@ -312,15 +321,16 @@ function storeHeader(self, state, field, value) {
312321
313322 if ( connectionExpression . test ( field ) ) {
314323 state . sentConnectionHeader = true ;
315- if ( closeExpression . test ( value ) ) {
324+ if ( connCloseExpression . test ( value ) ) {
316325 self . _last = true ;
317326 } else {
318327 self . shouldKeepAlive = true ;
319328 }
320-
329+ if ( connUpgradeExpression . test ( value ) )
330+ state . sentConnectionUpgrade = true ;
321331 } else if ( transferEncodingExpression . test ( field ) ) {
322332 state . sentTransferEncodingHeader = true ;
323- if ( chunkExpression . test ( value ) ) self . chunkedEncoding = true ;
333+ if ( trfrEncChunkExpression . test ( value ) ) self . chunkedEncoding = true ;
324334
325335 } else if ( contentLengthExpression . test ( field ) ) {
326336 state . sentContentLengthHeader = true ;
@@ -330,6 +340,8 @@ function storeHeader(self, state, field, value) {
330340 state . sentExpect = true ;
331341 } else if ( trailerExpression . test ( field ) ) {
332342 state . sentTrailer = true ;
343+ } else if ( upgradeExpression . test ( field ) ) {
344+ state . sentUpgrade = true ;
333345 }
334346}
335347
0 commit comments