Skip to content

Commit e0d9994

Browse files
committed
Merge pull request #27 from dpovshed/patch-1
Small fix to emitter of 'data' event
2 parents 4f42ccc + 6781887 commit e0d9994

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@ Interesting events emitted by Request:
1717

1818
* `response`: The response headers were received from the server and successfully
1919
parsed. The first argument is a Response instance.
20-
* `error`: An error occured.
21-
* `end`: The request is finished. If an error occured, it is passed as first
20+
* `error`: An error occurred.
21+
* `end`: The request is finished. If an error occurred, it is passed as first
2222
argument. Second and third arguments are the Response and the Request.
2323

2424
Interesting events emitted by Response:
2525

26-
* `data`: Passes a chunk of the response body as first argument
27-
* `error`: An error occured.
26+
* `data`: Passes a chunk of the response body as first argument and a Response
27+
object itself as second argument.
28+
* `error`: An error occurred.
2829
* `end`: The response has been fully received. If an error
29-
occured, it is passed as first argument
30+
occurred, it is passed as first argument.
3031

3132
### Example
3233

@@ -43,7 +44,7 @@ $client = $factory->create($loop, $dnsResolver);
4344

4445
$request = $client->request('GET', 'https://github.com/');
4546
$request->on('response', function ($response) {
46-
$response->on('data', function ($data) {
47+
$response->on('data', function ($data, $response) {
4748
// ...
4849
});
4950
});

src/Request.php

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

148148
$this->emit('response', array($response, $this));
149149

150-
$response->emit('data', array($bodyChunk));
150+
$response->emit('data', array($bodyChunk, $response));
151151
}
152152
}
153153

src/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use React\Stream\WritableStreamInterface;
1010

1111
/**
12-
* @event data
12+
* @event data ($bodyChunk, Response $thisResponse)
1313
* @event error
1414
* @event end
1515
*/

tests/RequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function requestShouldBindToStreamEventsAndUseconnector()
7171

7272
$response->expects($this->once())
7373
->method('emit')
74-
->with('data', array('body'));
74+
->with('data', array('body', $response));
7575

7676
$response->expects($this->at(0))
7777
->method('on')

0 commit comments

Comments
 (0)