Skip to content

Commit 243015b

Browse files
authored
Ensure the first bit of body directly after the headers is emitted into 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)
1 parent 07fa19d commit 243015b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function handleData($data)
156156

157157
$this->emit('response', array($response, $this));
158158

159-
$response->emit('data', array($bodyChunk, $response));
159+
$this->stream->emit('data', array($bodyChunk));
160160
}
161161
}
162162

tests/RequestTest.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public function requestShouldBindToStreamEventsAndUseconnector()
7171

7272
$response = $this->response;
7373

74-
$response->expects($this->once())
74+
$this->stream->expects($this->once())
7575
->method('emit')
76-
->with('data', $this->identicalTo(array('body', $response)));
76+
->with('data', $this->identicalTo(array('body')));
7777

7878
$response->expects($this->at(0))
7979
->method('on')
@@ -533,4 +533,25 @@ public function multivalueHeader()
533533
$this->assertNotNull($errorCallback);
534534
call_user_func($errorCallback, new \Exception('test'));
535535
}
536+
537+
/** @test */
538+
public function chunkedStreamDecoder()
539+
{
540+
$requestData = new RequestData('GET', 'http://www.example.com');
541+
$request = new Request($this->connector, $requestData);
542+
543+
$this->successfulConnectionMock();
544+
545+
$request->end();
546+
547+
$this->stream->expects($this->once())
548+
->method('emit')
549+
->with('data', ["1\r\nb\r"]);
550+
551+
$request->handleData("HTTP/1.0 200 OK\r\n");
552+
$request->handleData("Transfer-Encoding: chunked\r\n");
553+
$request->handleData("\r\n1\r\nb\r");
554+
$request->handleData("\n3\t\nody\r\n0\t\n\r\n");
555+
556+
}
536557
}

0 commit comments

Comments
 (0)