Skip to content

Commit

Permalink
Ensure the first bit of body directly after the headers is emitted in…
Browse files Browse the repository at this point in the history
…to the stream (#68)

* Fix #67 caused by the little bit of body coming with the headers not emitted from the stream but from the response never making it into the stream

* $response should not be emitted here, that will happen again once the data flowed through the stream into the response: #68 (comment)
  • Loading branch information
WyriHaximus authored Oct 28, 2016
1 parent 07fa19d commit 243015b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
25 changes: 23 additions & 2 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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");

}
}

0 comments on commit 243015b

Please sign in to comment.