@@ -92,7 +92,7 @@ function onStreamError(error) {
9292 // errors in compatibility mode are
9393 // not forwarded to the request
9494 // and response objects. However,
95- // they are forwarded to 'clientError '
95+ // they are forwarded to 'streamError '
9696 // on the server by Http2Stream
9797}
9898
@@ -248,9 +248,9 @@ class Http2ServerRequest extends Readable {
248248 }
249249
250250 setTimeout ( msecs , callback ) {
251- const stream = this [ kStream ] ;
252- if ( stream === undefined ) return ;
253- stream . setTimeout ( msecs , callback ) ;
251+ if ( this [ kState ] . closed )
252+ return ;
253+ this [ kStream ] . setTimeout ( msecs , callback ) ;
254254 }
255255
256256 [ kFinish ] ( code ) {
@@ -445,7 +445,7 @@ class Http2ServerResponse extends Stream {
445445
446446 if ( stream === undefined ) {
447447 const err = new errors . Error ( 'ERR_HTTP2_STREAM_CLOSED' ) ;
448- if ( cb )
448+ if ( typeof cb === 'function' )
449449 process . nextTick ( cb , err ) ;
450450 else
451451 throw err ;
@@ -461,12 +461,11 @@ class Http2ServerResponse extends Stream {
461461 if ( typeof chunk === 'function' ) {
462462 cb = chunk ;
463463 chunk = null ;
464- encoding = 'utf8' ;
465464 } else if ( typeof encoding === 'function' ) {
466465 cb = encoding ;
467466 encoding = 'utf8' ;
468467 }
469- if ( stream === undefined || stream . finished === true ) {
468+ if ( this . finished === true ) {
470469 return false ;
471470 }
472471 if ( chunk !== null && chunk !== undefined ) {
@@ -482,21 +481,21 @@ class Http2ServerResponse extends Stream {
482481 }
483482
484483 destroy ( err ) {
485- const stream = this [ kStream ] ;
486- if ( stream === undefined ) {
487- // nothing to do, already closed
484+ if ( this [ kState ] . closed )
488485 return ;
489- }
490- stream . destroy ( err ) ;
486+ this [ kStream ] . destroy ( err ) ;
491487 }
492488
493489 setTimeout ( msecs , callback ) {
494490 const stream = this [ kStream ] ;
495- if ( stream === undefined ) return ;
491+ if ( this [ kState ] . closed )
492+ return ;
496493 stream . setTimeout ( msecs , callback ) ;
497494 }
498495
499496 createPushResponse ( headers , callback ) {
497+ if ( typeof callback !== 'function' )
498+ throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
500499 const stream = this [ kStream ] ;
501500 if ( stream === undefined ) {
502501 process . nextTick ( callback , new errors . Error ( 'ERR_HTTP2_STREAM_CLOSED' ) ) ;
@@ -513,12 +512,9 @@ class Http2ServerResponse extends Stream {
513512 if ( stream !== undefined &&
514513 stream . destroyed === false &&
515514 stream . headersSent === false ) {
516- options = options || Object . create ( null ) ;
517- const state = this [ kState ] ;
518515 const headers = this [ kHeaders ] ;
519- headers [ HTTP2_HEADER_STATUS ] = state . statusCode ;
520- if ( stream . finished === true )
521- options . endStream = true ;
516+ headers [ HTTP2_HEADER_STATUS ] = this [ kState ] . statusCode ;
517+ options = options || Object . create ( null ) ;
522518 options . getTrailers = ( trailers ) => {
523519 Object . assign ( trailers , this [ kTrailers ] ) ;
524520 } ;
@@ -542,7 +538,11 @@ class Http2ServerResponse extends Stream {
542538 // TODO doesn't support callbacks
543539 writeContinue ( ) {
544540 const stream = this [ kStream ] ;
545- if ( stream === undefined ) return false ;
541+ if ( stream === undefined ||
542+ stream . headersSent === true ||
543+ stream . destroyed === true ) {
544+ return false ;
545+ }
546546 this [ kStream ] . additionalHeaders ( {
547547 [ HTTP2_HEADER_STATUS ] : HTTP_STATUS_CONTINUE
548548 } ) ;
0 commit comments