Skip to content

Commit 9ad66e5

Browse files
committed
[HttpClient] Fix "Undefined array key ..." when processing a NativeResponse
1 parent cf4ef92 commit 9ad66e5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function __construct(NativeClientState $multi, $context, string $url, arr
7979
};
8080

8181
$this->canary = new Canary(static function () use ($multi, $id) {
82-
if (null !== ($host = $multi->openHandles[$id][6] ?? null) && 0 >= --$multi->hosts[$host]) {
82+
if (null !== ($host = $multi->openHandles[$id][6] ?? null) && isset($multi->hosts[$host]) && 0 >= --$multi->hosts[$host]) {
8383
unset($multi->hosts[$host]);
8484
}
8585
unset($multi->openHandles[$id], $multi->handlesActivity[$id]);
@@ -302,7 +302,7 @@ private static function perform(ClientState $multi, ?array &$responses = null):
302302

303303
$multi->handlesActivity[$i][] = null;
304304
$multi->handlesActivity[$i][] = $e;
305-
if (null !== ($host = $multi->openHandles[$i][6] ?? null) && 0 >= --$multi->hosts[$host]) {
305+
if (null !== ($host = $multi->openHandles[$i][6] ?? null) && isset($multi->hosts[$host]) && 0 >= --$multi->hosts[$host]) {
306306
unset($multi->hosts[$host]);
307307
}
308308
unset($multi->openHandles[$i]);

src/Symfony/Component/HttpClient/Tests/NativeHttpClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,22 @@ public function testHttp2PushVulcainWithUnusedResponse()
4545
{
4646
$this->markTestSkipped('NativeHttpClient doesn\'t support HTTP/2.');
4747
}
48+
49+
/**
50+
* Because the HttpClientDataCollector resets the client when collecting data, we need to ensure that the response
51+
* can be processed before and after the reset.
52+
* This test will fail with "Undefined array key "127.0.0.1"" if broken.
53+
*/
54+
public function testResponseCanBeProcessedAfterClientReset()
55+
{
56+
$client = $this->getHttpClient(__FUNCTION__);
57+
$response = $client->request('GET', 'http://127.0.0.1:8057/timeout-body');
58+
$stream = $client->stream($response);
59+
60+
$response->getStatusCode();
61+
$client->reset(); // Simulate a reset done by the HttpClientDataCollector
62+
$stream->current();
63+
64+
$this->addToAssertionCount(1);
65+
}
4866
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy