Skip to content

Commit c31015e

Browse files
[HttpClient] fix tests and merge
1 parent 8a70d35 commit c31015e

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\HttpClient\Exception\TransportException;
2929
use Symfony\Component\HttpClient\HttpClientTrait;
3030
use Symfony\Component\HttpClient\Internal\AmpBody;
31+
use Symfony\Component\HttpClient\Internal\AmpCanary;
3132
use Symfony\Component\HttpClient\Internal\AmpClientState;
3233
use Symfony\Component\HttpClient\Internal\ClientState;
3334
use Symfony\Contracts\HttpClient\ResponseInterface;
@@ -141,13 +142,17 @@ public function __destruct()
141142
try {
142143
$this->doDestruct();
143144
} finally {
145+
$multi = clone $this->multi;
146+
144147
$this->close();
145148

146149
// Clear the DNS cache when all requests completed
147150
if (0 >= --$this->multi->responseCount) {
148151
$this->multi->responseCount = 0;
149152
$this->multi->dnsCache = [];
150153
}
154+
155+
$this->multi = $multi;
151156
}
152157
}
153158

@@ -222,11 +227,9 @@ private static function select(ClientState $multi, float $timeout): int
222227

223228
private static function generateResponse(Request $request, AmpClientState $multi, string $id, array &$info, array &$headers, CancellationTokenSource $canceller, array &$options, \Closure $onProgress, &$handle, ?LoggerInterface $logger, Promise &$pause)
224229
{
225-
$activity = &$multi->handlesActivity;
226-
227-
$request->setInformationalResponseHandler(static function (Response $response) use (&$activity, $id, &$info, &$headers) {
230+
$request->setInformationalResponseHandler(static function (Response $response) use ($multi, $id, &$info, &$headers) {
228231
self::addResponseHeaders($response, $info, $headers);
229-
$activity[$id][] = new InformationalChunk($response->getStatus(), $response->getHeaders());
232+
$multi->handlesActivity[$id][] = new InformationalChunk($response->getStatus(), $response->getHeaders());
230233
self::stopLoop();
231234
});
232235

@@ -240,11 +243,11 @@ private static function generateResponse(Request $request, AmpClientState $multi
240243

241244
$options = null;
242245

243-
$activity[$id][] = new FirstChunk();
246+
$multi->handlesActivity[$id][] = new FirstChunk();
244247

245248
if ('HEAD' === $response->getRequest()->getMethod() || \in_array($info['http_code'], [204, 304], true)) {
246-
$activity[$id][] = null;
247-
$activity[$id][] = null;
249+
$multi->handlesActivity[$id][] = null;
250+
$multi->handlesActivity[$id][] = null;
248251
self::stopLoop();
249252

250253
return;
@@ -266,14 +269,14 @@ private static function generateResponse(Request $request, AmpClientState $multi
266269
}
267270

268271
$info['size_download'] += \strlen($data);
269-
$activity[$id][] = $data;
272+
$multi->handlesActivity[$id][] = $data;
270273
}
271274

272-
$activity[$id][] = null;
273-
$activity[$id][] = null;
275+
$multi->handlesActivity[$id][] = null;
276+
$multi->handlesActivity[$id][] = null;
274277
} catch (\Throwable $e) {
275-
$activity[$id][] = null;
276-
$activity[$id][] = $e;
278+
$multi->handlesActivity[$id][] = null;
279+
$multi->handlesActivity[$id][] = $e;
277280
} finally {
278281
$info['download_content_length'] = $info['size_download'];
279282
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public function __construct(HttpClientInterface $client, string $method, string
6666
return false;
6767
}
6868
}
69-
}
7069

71-
return false;
70+
return false;
71+
}
7272
};
7373
if (\array_key_exists('user_data', $options)) {
7474
$this->info['user_data'] = $options['user_data'];
@@ -175,7 +175,6 @@ public function __destruct()
175175

176176
if ($this->passthru && null === $this->getInfo('error')) {
177177
$this->info['canceled'] = true;
178-
$this->info['error'] = 'Response has been canceled.';
179178

180179
try {
181180
foreach (self::passthru($this->client, $this, new LastChunk()) as $chunk) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class AsyncDecoratorTraitTest extends NativeHttpClientTest
2424
{
2525
protected function getHttpClient(string $testCase, \Closure $chunkFilter = null): HttpClientInterface
2626
{
27+
if ('testHandleIsRemovedOnException' === $testCase) {
28+
$this->markTestSkipped("AsyncDecoratorTrait doesn't cache handles");
29+
}
30+
2731
$chunkFilter = $chunkFilter ?? static function (ChunkInterface $chunk, AsyncContext $context) { yield $chunk; };
2832

2933
return new class(parent::getHttpClient($testCase), $chunkFilter) implements HttpClientInterface {
@@ -227,7 +231,7 @@ public function testRetryTimeout()
227231
} else {
228232
$context->passthru();
229233
$context->getResponse()->cancel();
230-
$context->replaceRequest('GET', 'http://localhost:8057/timeout-header', ['timeout' => 1]);
234+
$context->replaceRequest('GET', 'http://localhost:8057/timeout-header', ['timeout' => 10]);
231235
}
232236
}
233237
});

0 commit comments

Comments
 (0)