@@ -462,7 +462,7 @@ public function testPostString()
462462 $ this ->assertEquals ('hello world ' , $ data ['data ' ]);
463463 }
464464
465- public function testReceiveStreamUntilConnectionsEndsForHttp10 ()
465+ public function testRequestStreamReturnsResponseBodyUntilConnectionsEndsForHttp10 ()
466466 {
467467 $ response = Block \await ($ this ->browser ->withProtocolVersion ('1.0 ' )->get ($ this ->base . 'stream/1 ' ), $ this ->loop );
468468
@@ -473,21 +473,47 @@ public function testReceiveStreamUntilConnectionsEndsForHttp10()
473473 $ this ->assertStringEndsWith ('} ' , (string ) $ response ->getBody ());
474474 }
475475
476- public function testReceiveStreamChunkedForHttp11 ()
476+ public function testRequestStreamReturnsResponseWithTransferEncodingChunkedAndResponseBodyDecodedForHttp11 ()
477477 {
478- $ response = Block \await ($ this ->browser ->request ( ' GET ' , $ this ->base . 'stream/1 ' ), $ this ->loop );
478+ $ response = Block \await ($ this ->browser ->get ( $ this ->base . 'stream/1 ' ), $ this ->loop );
479479
480480 $ this ->assertEquals ('1.1 ' , $ response ->getProtocolVersion ());
481481
482- // underlying http-client automatically decodes and doesn't expose header
483- // @link https://github.com/reactphp/http-client/pull/58
484- // $this->assertEquals('chunked', $response->getHeaderLine('Transfer-Encoding'));
485- $ this ->assertFalse ($ response ->hasHeader ('Transfer-Encoding ' ));
482+ $ this ->assertEquals ('chunked ' , $ response ->getHeaderLine ('Transfer-Encoding ' ));
486483
487484 $ this ->assertStringStartsWith ('{ ' , (string ) $ response ->getBody ());
488485 $ this ->assertStringEndsWith ('} ' , (string ) $ response ->getBody ());
489486 }
490487
488+ public function testRequestStreamWithHeadRequestReturnsEmptyResponseBodWithTransferEncodingChunkedForHttp11 ()
489+ {
490+ $ response = Block \await ($ this ->browser ->head ($ this ->base . 'stream/1 ' ), $ this ->loop );
491+
492+ $ this ->assertEquals ('1.1 ' , $ response ->getProtocolVersion ());
493+
494+ $ this ->assertEquals ('chunked ' , $ response ->getHeaderLine ('Transfer-Encoding ' ));
495+ $ this ->assertEquals ('' , (string ) $ response ->getBody ());
496+ }
497+
498+ public function testRequestStreamReturnsResponseWithResponseBodyUndecodedWhenResponseHasDoubleTransferEncoding ()
499+ {
500+ $ socket = new \React \Socket \Server (0 , $ this ->loop );
501+ $ socket ->on ('connection ' , function (\React \Socket \ConnectionInterface $ connection ) {
502+ $ connection ->on ('data ' , function () use ($ connection ) {
503+ $ connection ->end ("HTTP/1.1 200 OK \r\nTransfer-Encoding: chunked, chunked \r\nConnection: close \r\n\r\nhello " );
504+ });
505+ });
506+
507+ $ this ->base = str_replace ('tcp: ' , 'http: ' , $ socket ->getAddress ()) . '/ ' ;
508+
509+ $ response = Block \await ($ this ->browser ->get ($ this ->base . 'stream/1 ' ), $ this ->loop );
510+
511+ $ this ->assertEquals ('1.1 ' , $ response ->getProtocolVersion ());
512+
513+ $ this ->assertEquals ('chunked, chunked ' , $ response ->getHeaderLine ('Transfer-Encoding ' ));
514+ $ this ->assertEquals ('hello ' , (string ) $ response ->getBody ());
515+ }
516+
491517 public function testReceiveStreamAndExplicitlyCloseConnectionEvenWhenServerKeepsConnectionOpen ()
492518 {
493519 $ closed = new \React \Promise \Deferred ();
0 commit comments