@@ -9,16 +9,18 @@ const Buffer = require('buffer').Buffer;
9
9
const common = require ( '_http_common' ) ;
10
10
11
11
const CRLF = common . CRLF ;
12
- const chunkExpression = common . chunkExpression ;
12
+ const trfrEncChunkExpression = common . chunkExpression ;
13
13
const debug = common . debug ;
14
14
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;
16
16
const 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;
18
17
const contentLengthExpression = / ^ C o n t e n t - L e n g t h $ / i;
19
18
const dateExpression = / ^ D a t e $ / i;
20
19
const expectExpression = / ^ E x p e c t $ / i;
21
20
const 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;
22
24
23
25
const automaticHeaders = {
24
26
connection : true ,
@@ -61,6 +63,7 @@ function OutgoingMessage() {
61
63
this . writable = true ;
62
64
63
65
this . _last = false ;
66
+ this . upgrading = false ;
64
67
this . chunkedEncoding = false ;
65
68
this . shouldKeepAlive = true ;
66
69
this . useChunkedEncodingByDefault = true ;
@@ -192,11 +195,13 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
192
195
// in the case of response it is: 'HTTP/1.1 200 OK\r\n'
193
196
var state = {
194
197
sentConnectionHeader : false ,
198
+ sentConnectionUpgrade : false ,
195
199
sentContentLengthHeader : false ,
196
200
sentTransferEncodingHeader : false ,
197
201
sentDateHeader : false ,
198
202
sentExpect : false ,
199
203
sentTrailer : false ,
204
+ sentUpgrade : false ,
200
205
messageHeader : firstLine
201
206
} ;
202
207
@@ -225,6 +230,10 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
225
230
}
226
231
}
227
232
233
+ // Are we upgrading the connection?
234
+ if ( state . sentConnectionUpgrade && state . sentUpgrade )
235
+ this . upgrading = true ;
236
+
228
237
// Date header
229
238
if ( this . sendDate === true && state . sentDateHeader === false ) {
230
239
state . messageHeader += 'Date: ' + utcDate ( ) + CRLF ;
@@ -312,15 +321,16 @@ function storeHeader(self, state, field, value) {
312
321
313
322
if ( connectionExpression . test ( field ) ) {
314
323
state . sentConnectionHeader = true ;
315
- if ( closeExpression . test ( value ) ) {
324
+ if ( connCloseExpression . test ( value ) ) {
316
325
self . _last = true ;
317
326
} else {
318
327
self . shouldKeepAlive = true ;
319
328
}
320
-
329
+ if ( connUpgradeExpression . test ( value ) )
330
+ state . sentConnectionUpgrade = true ;
321
331
} else if ( transferEncodingExpression . test ( field ) ) {
322
332
state . sentTransferEncodingHeader = true ;
323
- if ( chunkExpression . test ( value ) ) self . chunkedEncoding = true ;
333
+ if ( trfrEncChunkExpression . test ( value ) ) self . chunkedEncoding = true ;
324
334
325
335
} else if ( contentLengthExpression . test ( field ) ) {
326
336
state . sentContentLengthHeader = true ;
@@ -330,6 +340,8 @@ function storeHeader(self, state, field, value) {
330
340
state . sentExpect = true ;
331
341
} else if ( trailerExpression . test ( field ) ) {
332
342
state . sentTrailer = true ;
343
+ } else if ( upgradeExpression . test ( field ) ) {
344
+ state . sentUpgrade = true ;
333
345
}
334
346
}
335
347
0 commit comments