@@ -2005,11 +2005,11 @@ class Http2Stream extends Duplex {
2005
2005
function processHeaders ( headers ) {
2006
2006
assertIsObject ( headers , 'headers' ) ;
2007
2007
headers = Object . assign ( Object . create ( null ) , headers ) ;
2008
- if ( headers [ HTTP2_HEADER_STATUS ] == null )
2009
- headers [ HTTP2_HEADER_STATUS ] = HTTP_STATUS_OK ;
2008
+ const statusCode =
2009
+ headers [ HTTP2_HEADER_STATUS ] =
2010
+ headers [ HTTP2_HEADER_STATUS ] | 0 || HTTP_STATUS_OK ;
2010
2011
headers [ HTTP2_HEADER_DATE ] = utcDate ( ) ;
2011
2012
2012
- const statusCode = headers [ HTTP2_HEADER_STATUS ] |= 0 ;
2013
2013
// This is intentionally stricter than the HTTP/1 implementation, which
2014
2014
// allows values between 100 and 999 (inclusive) in order to allow for
2015
2015
// backwards compatibility with non-spec compliant code. With HTTP/2,
@@ -2342,26 +2342,22 @@ class ServerHttp2Stream extends Http2Stream {
2342
2342
}
2343
2343
2344
2344
headers = processHeaders ( headers ) ;
2345
- const statusCode = headers [ HTTP2_HEADER_STATUS ] |= 0 ;
2346
-
2347
- // Payload/DATA frames are not permitted in these cases so set
2348
- // the options.endStream option to true so that the underlying
2349
- // bits do not attempt to send any.
2350
- if ( statusCode === HTTP_STATUS_NO_CONTENT ||
2351
- statusCode === HTTP_STATUS_RESET_CONTENT ||
2352
- statusCode === HTTP_STATUS_NOT_MODIFIED ||
2353
- this . headRequest === true ) {
2354
- options . endStream = true ;
2355
- }
2356
-
2357
2345
const headersList = mapToHeaders ( headers , assertValidPseudoHeaderResponse ) ;
2358
2346
this [ kSentHeaders ] = headers ;
2359
2347
2360
2348
state . flags |= STREAM_FLAGS_HEADERS_SENT ;
2361
2349
2362
- // Close the writable side if the endStream option is set
2363
- if ( options . endStream )
2350
+ // Close the writable side if the endStream option is set or status
2351
+ // is one of known codes with no payload, or it's a head request
2352
+ const statusCode = headers [ HTTP2_HEADER_STATUS ] | 0 ;
2353
+ if ( ! ! options . endStream ||
2354
+ statusCode === HTTP_STATUS_NO_CONTENT ||
2355
+ statusCode === HTTP_STATUS_RESET_CONTENT ||
2356
+ statusCode === HTTP_STATUS_NOT_MODIFIED ||
2357
+ this . headRequest === true ) {
2358
+ options . endStream = true ;
2364
2359
this . end ( ) ;
2360
+ }
2365
2361
2366
2362
const ret = this [ kHandle ] . respond ( headersList , streamOptions ) ;
2367
2363
if ( ret < 0 )
@@ -2414,7 +2410,8 @@ class ServerHttp2Stream extends Http2Stream {
2414
2410
// Payload/DATA frames are not permitted in these cases
2415
2411
if ( statusCode === HTTP_STATUS_NO_CONTENT ||
2416
2412
statusCode === HTTP_STATUS_RESET_CONTENT ||
2417
- statusCode === HTTP_STATUS_NOT_MODIFIED ) {
2413
+ statusCode === HTTP_STATUS_NOT_MODIFIED ||
2414
+ this . headRequest ) {
2418
2415
throw new ERR_HTTP2_PAYLOAD_FORBIDDEN ( statusCode ) ;
2419
2416
}
2420
2417
@@ -2475,7 +2472,8 @@ class ServerHttp2Stream extends Http2Stream {
2475
2472
// Payload/DATA frames are not permitted in these cases
2476
2473
if ( statusCode === HTTP_STATUS_NO_CONTENT ||
2477
2474
statusCode === HTTP_STATUS_RESET_CONTENT ||
2478
- statusCode === HTTP_STATUS_NOT_MODIFIED ) {
2475
+ statusCode === HTTP_STATUS_NOT_MODIFIED ||
2476
+ this . headRequest ) {
2479
2477
throw new ERR_HTTP2_PAYLOAD_FORBIDDEN ( statusCode ) ;
2480
2478
}
2481
2479
0 commit comments