Skip to content

[HttpClient] Added notes about handling errors when multiplexing responses #12896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions components/http_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ the "foreach" in the snippet with this one, the code becomes fully async::

foreach ($client->stream($responses) as $response => $chunk) {
if ($chunk->isFirst()) {
if (400 <= $response->getStatusCode()) {
// here can be handled case when request was respond
// with 4xx-5xx status code
// for example $response->cancel() may be called
// to prevent subsequent handling of this response
}
// headers of $response just arrived
// $response->getHeaders() is now a non-blocking call
} elseif ($chunk->isLast()) {
Expand Down Expand Up @@ -516,6 +522,11 @@ response and get remaining contents that might come back in a new timeout, etc.
is idle*. Big responses can last as long as needed to complete, provided they
remain active during the transfer and never pause for longer than specified.

.. note::

When multiplexing responses, you should check timeout firstly, before
``isFirst``/``isLast``.

Dealing with Network Errors
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down