28
28
use Symfony \Component \HttpClient \Exception \TransportException ;
29
29
use Symfony \Component \HttpClient \HttpClientTrait ;
30
30
use Symfony \Component \HttpClient \Internal \AmpBody ;
31
+ use Symfony \Component \HttpClient \Internal \AmpCanary ;
31
32
use Symfony \Component \HttpClient \Internal \AmpClientState ;
32
33
use Symfony \Component \HttpClient \Internal \ClientState ;
33
34
use Symfony \Contracts \HttpClient \ResponseInterface ;
@@ -141,13 +142,17 @@ public function __destruct()
141
142
try {
142
143
$ this ->doDestruct ();
143
144
} finally {
145
+ $ multi = clone $ this ->multi ;
146
+
144
147
$ this ->close ();
145
148
146
149
// Clear the DNS cache when all requests completed
147
150
if (0 >= --$ this ->multi ->responseCount ) {
148
151
$ this ->multi ->responseCount = 0 ;
149
152
$ this ->multi ->dnsCache = [];
150
153
}
154
+
155
+ $ this ->multi = $ multi ;
151
156
}
152
157
}
153
158
@@ -222,11 +227,9 @@ private static function select(ClientState $multi, float $timeout): int
222
227
223
228
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 )
224
229
{
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 ) {
228
231
self ::addResponseHeaders ($ response , $ info , $ headers );
229
- $ activity [$ id ][] = new InformationalChunk ($ response ->getStatus (), $ response ->getHeaders ());
232
+ $ multi -> handlesActivity [$ id ][] = new InformationalChunk ($ response ->getStatus (), $ response ->getHeaders ());
230
233
self ::stopLoop ();
231
234
});
232
235
@@ -240,11 +243,11 @@ private static function generateResponse(Request $request, AmpClientState $multi
240
243
241
244
$ options = null ;
242
245
243
- $ activity [$ id ][] = new FirstChunk ();
246
+ $ multi -> handlesActivity [$ id ][] = new FirstChunk ();
244
247
245
248
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 ;
248
251
self ::stopLoop ();
249
252
250
253
return ;
@@ -266,14 +269,14 @@ private static function generateResponse(Request $request, AmpClientState $multi
266
269
}
267
270
268
271
$ info ['size_download ' ] += \strlen ($ data );
269
- $ activity [$ id ][] = $ data ;
272
+ $ multi -> handlesActivity [$ id ][] = $ data ;
270
273
}
271
274
272
- $ activity [$ id ][] = null ;
273
- $ activity [$ id ][] = null ;
275
+ $ multi -> handlesActivity [$ id ][] = null ;
276
+ $ multi -> handlesActivity [$ id ][] = null ;
274
277
} catch (\Throwable $ e ) {
275
- $ activity [$ id ][] = null ;
276
- $ activity [$ id ][] = $ e ;
278
+ $ multi -> handlesActivity [$ id ][] = null ;
279
+ $ multi -> handlesActivity [$ id ][] = $ e ;
277
280
} finally {
278
281
$ info ['download_content_length ' ] = $ info ['size_download ' ];
279
282
}
0 commit comments