@@ -2005,11 +2005,11 @@ class Http2Stream extends Duplex {
20052005function processHeaders ( headers ) {
20062006 assertIsObject ( headers , 'headers' ) ;
20072007 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 ;
20102011 headers [ HTTP2_HEADER_DATE ] = utcDate ( ) ;
20112012
2012- const statusCode = headers [ HTTP2_HEADER_STATUS ] |= 0 ;
20132013 // This is intentionally stricter than the HTTP/1 implementation, which
20142014 // allows values between 100 and 999 (inclusive) in order to allow for
20152015 // backwards compatibility with non-spec compliant code. With HTTP/2,
@@ -2342,26 +2342,22 @@ class ServerHttp2Stream extends Http2Stream {
23422342 }
23432343
23442344 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-
23572345 const headersList = mapToHeaders ( headers , assertValidPseudoHeaderResponse ) ;
23582346 this [ kSentHeaders ] = headers ;
23592347
23602348 state . flags |= STREAM_FLAGS_HEADERS_SENT ;
23612349
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 ;
23642359 this . end ( ) ;
2360+ }
23652361
23662362 const ret = this [ kHandle ] . respond ( headersList , streamOptions ) ;
23672363 if ( ret < 0 )
@@ -2414,7 +2410,8 @@ class ServerHttp2Stream extends Http2Stream {
24142410 // Payload/DATA frames are not permitted in these cases
24152411 if ( statusCode === HTTP_STATUS_NO_CONTENT ||
24162412 statusCode === HTTP_STATUS_RESET_CONTENT ||
2417- statusCode === HTTP_STATUS_NOT_MODIFIED ) {
2413+ statusCode === HTTP_STATUS_NOT_MODIFIED ||
2414+ this . headRequest ) {
24182415 throw new ERR_HTTP2_PAYLOAD_FORBIDDEN ( statusCode ) ;
24192416 }
24202417
@@ -2475,7 +2472,8 @@ class ServerHttp2Stream extends Http2Stream {
24752472 // Payload/DATA frames are not permitted in these cases
24762473 if ( statusCode === HTTP_STATUS_NO_CONTENT ||
24772474 statusCode === HTTP_STATUS_RESET_CONTENT ||
2478- statusCode === HTTP_STATUS_NOT_MODIFIED ) {
2475+ statusCode === HTTP_STATUS_NOT_MODIFIED ||
2476+ this . headRequest ) {
24792477 throw new ERR_HTTP2_PAYLOAD_FORBIDDEN ( statusCode ) ;
24802478 }
24812479
0 commit comments