@@ -44,8 +44,11 @@ Interesting events emitted by Request:
44
44
* ` drain ` : The outgoing buffer drained and the response is ready to accept more
45
45
data for the next ` write() ` call.
46
46
* ` 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.
47
48
* ` close ` : The request is closed. If an error occurred, this event will be
48
49
preceeded by an ` error ` event.
50
+ For a successful response, this will be emitted only once the response emits
51
+ the ` close ` event.
49
52
50
53
Response implements ReadableStreamInterface.
51
54
Interesting events emitted by Response:
@@ -54,9 +57,11 @@ Interesting events emitted by Response:
54
57
When a response encounters a chunked encoded response it will parse it
55
58
transparently for the user and removing the ` Transfer-Encoding ` header.
56
59
* ` 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.
57
61
* ` end ` : The response has been fully received.
58
62
* ` close ` : The response is closed. If an error occured, this event will be
59
63
preceeded by an ` error ` event.
64
+ This will also be forwarded to the request and emit a ` close ` event there.
60
65
61
66
### Example
62
67
@@ -68,9 +73,15 @@ $client = new React\HttpClient\Client($loop);
68
73
69
74
$request = $client->request('GET', 'https://github.com/');
70
75
$request->on('response', function ($response) {
71
- $response->on('data', function ($data, $response ) {
72
- // ...
76
+ $response->on('data', function ($chunk ) {
77
+ echo $chunk;
73
78
});
79
+ $response->on('end', function() {
80
+ echo 'DONE';
81
+ });
82
+ });
83
+ $request->on('error', function (\Exception $e) {
84
+ echo $e;
74
85
});
75
86
$request->end();
76
87
$loop->run();
0 commit comments