diff --git a/src/Request.php b/src/Request.php index 11ca868..cdeb80c 100644 --- a/src/Request.php +++ b/src/Request.php @@ -156,7 +156,7 @@ public function handleData($data) $this->emit('response', array($response, $this)); - $response->emit('data', array($bodyChunk, $response)); + $this->stream->emit('data', array($bodyChunk)); } } diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 1d833d6..7572a8a 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -71,9 +71,9 @@ public function requestShouldBindToStreamEventsAndUseconnector() $response = $this->response; - $response->expects($this->once()) + $this->stream->expects($this->once()) ->method('emit') - ->with('data', $this->identicalTo(array('body', $response))); + ->with('data', $this->identicalTo(array('body'))); $response->expects($this->at(0)) ->method('on') @@ -533,4 +533,25 @@ public function multivalueHeader() $this->assertNotNull($errorCallback); call_user_func($errorCallback, new \Exception('test')); } + + /** @test */ + public function chunkedStreamDecoder() + { + $requestData = new RequestData('GET', 'http://www.example.com'); + $request = new Request($this->connector, $requestData); + + $this->successfulConnectionMock(); + + $request->end(); + + $this->stream->expects($this->once()) + ->method('emit') + ->with('data', ["1\r\nb\r"]); + + $request->handleData("HTTP/1.0 200 OK\r\n"); + $request->handleData("Transfer-Encoding: chunked\r\n"); + $request->handleData("\r\n1\r\nb\r"); + $request->handleData("\n3\t\nody\r\n0\t\n\r\n"); + + } }