@@ -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
const lenientHttpHeaders = ! ! process . REVERT_CVE_2016_2216 ;
23
25
24
26
const automaticHeaders = {
@@ -62,6 +64,7 @@ function OutgoingMessage() {
62
64
this . writable = true ;
63
65
64
66
this . _last = false ;
67
+ this . upgrading = false ;
65
68
this . chunkedEncoding = false ;
66
69
this . shouldKeepAlive = true ;
67
70
this . useChunkedEncodingByDefault = true ;
@@ -191,11 +194,13 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
191
194
// in the case of response it is: 'HTTP/1.1 200 OK\r\n'
192
195
var state = {
193
196
sentConnectionHeader : false ,
197
+ sentConnectionUpgrade : false ,
194
198
sentContentLengthHeader : false ,
195
199
sentTransferEncodingHeader : false ,
196
200
sentDateHeader : false ,
197
201
sentExpect : false ,
198
202
sentTrailer : false ,
203
+ sentUpgrade : false ,
199
204
messageHeader : firstLine
200
205
} ;
201
206
@@ -224,6 +229,10 @@ OutgoingMessage.prototype._storeHeader = function(firstLine, headers) {
224
229
}
225
230
}
226
231
232
+ // Are we upgrading the connection?
233
+ if ( state . sentConnectionUpgrade && state . sentUpgrade )
234
+ this . upgrading = true ;
235
+
227
236
// Date header
228
237
if ( this . sendDate === true && state . sentDateHeader === false ) {
229
238
state . messageHeader += 'Date: ' + utcDate ( ) + CRLF ;
@@ -313,15 +322,16 @@ function storeHeader(self, state, field, value) {
313
322
314
323
if ( connectionExpression . test ( field ) ) {
315
324
state . sentConnectionHeader = true ;
316
- if ( closeExpression . test ( value ) ) {
325
+ if ( connCloseExpression . test ( value ) ) {
317
326
self . _last = true ;
318
327
} else {
319
328
self . shouldKeepAlive = true ;
320
329
}
321
-
330
+ if ( connUpgradeExpression . test ( value ) )
331
+ state . sentConnectionUpgrade = true ;
322
332
} else if ( transferEncodingExpression . test ( field ) ) {
323
333
state . sentTransferEncodingHeader = true ;
324
- if ( chunkExpression . test ( value ) ) self . chunkedEncoding = true ;
334
+ if ( trfrEncChunkExpression . test ( value ) ) self . chunkedEncoding = true ;
325
335
326
336
} else if ( contentLengthExpression . test ( field ) ) {
327
337
state . sentContentLengthHeader = true ;
@@ -331,6 +341,8 @@ function storeHeader(self, state, field, value) {
331
341
state . sentExpect = true ;
332
342
} else if ( trailerExpression . test ( field ) ) {
333
343
state . sentTrailer = true ;
344
+ } else if ( upgradeExpression . test ( field ) ) {
345
+ state . sentUpgrade = true ;
334
346
}
335
347
}
336
348
0 commit comments