Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0a4521e

Browse filesBrowse files
Jean-Berunicolas-grekas
authored andcommitted
[HttpClient] Fix processing a NativeResponse after its client has been reset
1 parent 4d4859a commit 0a4521e
Copy full SHA for 0a4521e

File tree

Expand file treeCollapse file tree

2 files changed

+19
-6
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+19
-6
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/NativeResponse.php
+6-6Lines changed: 6 additions & 6 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]);
@@ -123,7 +123,7 @@ private function open(): void
123123
throw new TransportException($msg);
124124
}
125125

126-
$this->logger?->info(sprintf('%s for "%s".', $msg, $url ?? $this->url));
126+
$this->logger?->info(\sprintf('%s for "%s".', $msg, $url ?? $this->url));
127127
});
128128

129129
try {
@@ -142,7 +142,7 @@ private function open(): void
142142
$this->info['request_header'] = $this->info['url']['path'].$this->info['url']['query'];
143143
}
144144

145-
$this->info['request_header'] = sprintf("> %s %s HTTP/%s \r\n", $context['http']['method'], $this->info['request_header'], $context['http']['protocol_version']);
145+
$this->info['request_header'] = \sprintf("> %s %s HTTP/%s \r\n", $context['http']['method'], $this->info['request_header'], $context['http']['protocol_version']);
146146
$this->info['request_header'] .= implode("\r\n", $context['http']['header'])."\r\n\r\n";
147147

148148
if (\array_key_exists('peer_name', $context['ssl']) && null === $context['ssl']['peer_name']) {
@@ -159,7 +159,7 @@ private function open(): void
159159
break;
160160
}
161161

162-
$this->logger?->info(sprintf('Redirecting: "%s %s"', $this->info['http_code'], $url ?? $this->url));
162+
$this->logger?->info(\sprintf('Redirecting: "%s %s"', $this->info['http_code'], $url ?? $this->url));
163163
}
164164
} catch (\Throwable $e) {
165165
$this->close();
@@ -294,15 +294,15 @@ private static function perform(ClientState $multi, ?array &$responses = null):
294294

295295
if (null === $e) {
296296
if (0 < $remaining) {
297-
$e = new TransportException(sprintf('Transfer closed with %s bytes remaining to read.', $remaining));
297+
$e = new TransportException(\sprintf('Transfer closed with %s bytes remaining to read.', $remaining));
298298
} elseif (-1 === $remaining && fwrite($buffer, '-') && '' !== stream_get_contents($buffer, -1, 0)) {
299299
$e = new TransportException('Transfer closed with outstanding data remaining from chunked response.');
300300
}
301301
}
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/HttpClientTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,4 +695,17 @@ public function testPostToGetRedirect(int $status)
695695
$this->assertSame('GET', $body['REQUEST_METHOD']);
696696
$this->assertSame('/', $body['REQUEST_URI']);
697697
}
698+
699+
public function testResponseCanBeProcessedAfterClientReset()
700+
{
701+
$client = $this->getHttpClient(__FUNCTION__);
702+
$response = $client->request('GET', 'http://127.0.0.1:8057/timeout-body');
703+
$stream = $client->stream($response);
704+
705+
$response->getStatusCode();
706+
$client->reset();
707+
$stream->current();
708+
709+
$this->addToAssertionCount(1);
710+
}
698711
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.