@@ -286,6 +286,9 @@ private function send(int $id, Response $response, Request $request, Cancellatio
286286 {
287287 $ chunk = "" ; // Required for the finally, not directly overwritten, even if your IDE says otherwise.
288288
289+ $ need = $ response ->getHeader ("content-length " );
290+ $ wrote = 0 ;
291+
289292 try {
290293 $ status = $ response ->getStatus ();
291294
@@ -333,6 +336,7 @@ private function send(int $id, Response $response, Request $request, Cancellatio
333336 if ($ request ->getMethod () === "HEAD " ) {
334337 $ this ->streams [$ id ]->state |= Http2Stream::LOCAL_CLOSED ;
335338 $ this ->writeData ("" , $ id );
339+ $ need = null ;
336340 return ;
337341 }
338342
@@ -344,6 +348,7 @@ private function send(int $id, Response $response, Request $request, Cancellatio
344348 if (!isset ($ this ->streams [$ id ])) {
345349 return ;
346350 }
351+ $ wrote += strlen ($ chunk );
347352
348353 $ this ->writeData ($ chunk , $ id );
349354
@@ -390,7 +395,7 @@ private function send(int $id, Response $response, Request $request, Cancellatio
390395 return ;
391396 }
392397
393- if ($ chunk !== null ) {
398+ if ($ chunk !== null || ( $ need !== null && $ wrote !== ( int ) $ need ) ) {
394399 $ error ??= Http2Parser::INTERNAL_ERROR ;
395400 $ this ->writeFrame (\pack ("N " , $ error ), Http2Parser::RST_STREAM , Http2Parser::NO_FLAG , $ id );
396401 $ this ->releaseStream ($ id , $ exception ?? new ClientException ($ this ->client , "Stream error " , $ error ));
0 commit comments