Skip to content

Commit ed7aabd

Browse files
committed
Added notes about multiplexing responses that contain ones with 4xx/5xx status codes and about handling timeout in the same case
1 parent f6ac446 commit ed7aabd

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

components/http_client.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,12 @@ the "foreach" in the snippet with this one, the code becomes fully async::
460460

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

525+
.. note::
526+
527+
When multiplexing responses, you should check timeout firstly, before
528+
``isFirst``/``isLast``.
529+
519530
Dealing with Network Errors
520531
~~~~~~~~~~~~~~~~~~~~~~~~~~~
521532

0 commit comments

Comments
 (0)