@@ -44,8 +44,11 @@ Interesting events emitted by Request:
4444* ` drain ` : The outgoing buffer drained and the response is ready to accept more
4545 data for the next ` write() ` call.
4646* ` error ` : An error occurred, an ` Exception ` is passed as first argument.
47+ If the response emits an ` error ` event, this will also be emitted here.
4748* ` close ` : The request is closed. If an error occurred, this event will be
4849 preceeded by an ` error ` event.
50+ For a successful response, this will be emitted only once the response emits
51+ the ` close ` event.
4952
5053Response implements ReadableStreamInterface.
5154Interesting events emitted by Response:
@@ -54,9 +57,11 @@ Interesting events emitted by Response:
5457 When a response encounters a chunked encoded response it will parse it
5558 transparently for the user and removing the ` Transfer-Encoding ` header.
5659* ` error ` : An error occurred, an ` Exception ` is passed as first argument.
60+ This will also be forwarded to the request and emit an ` error ` event there.
5761* ` end ` : The response has been fully received.
5862* ` close ` : The response is closed. If an error occured, this event will be
5963 preceeded by an ` error ` event.
64+ This will also be forwarded to the request and emit a ` close ` event there.
6065
6166### Example
6267
@@ -68,9 +73,15 @@ $client = new React\HttpClient\Client($loop);
6873
6974$request = $client->request('GET', 'https://github.com/');
7075$request->on('response', function ($response) {
71- $response->on('data', function ($data, $response ) {
72- // ...
76+ $response->on('data', function ($chunk ) {
77+ echo $chunk;
7378 });
79+ $response->on('end', function() {
80+ echo 'DONE';
81+ });
82+ });
83+ $request->on('error', function (\Exception $e) {
84+ echo $e;
7485});
7586$request->end();
7687$loop->run();
0 commit comments