24
24
use Symfony \Component \HttpClient \Exception \TransportException ;
25
25
use Symfony \Component \HttpClient \HttpClientTrait ;
26
26
use Symfony \Component \HttpClient \Internal \AmpBody ;
27
+ use Symfony \Component \HttpClient \Internal \AmpCanary ;
27
28
use Symfony \Component \HttpClient \Internal \AmpClientState ;
28
29
use Symfony \Component \HttpClient \Internal \ClientState ;
29
30
use Symfony \Contracts \HttpClient \ResponseInterface ;
@@ -108,13 +109,17 @@ public function __destruct()
108
109
try {
109
110
$ this ->doDestruct ();
110
111
} finally {
112
+ $ multi = clone $ this ->multi ;
113
+
111
114
$ this ->close ();
112
115
113
116
// Clear the DNS cache when all requests completed
114
117
if (0 >= --$ this ->multi ->responseCount ) {
115
118
$ this ->multi ->responseCount = 0 ;
116
119
$ this ->multi ->dnsCache = [];
117
120
}
121
+
122
+ $ this ->multi = $ multi ;
118
123
}
119
124
}
120
125
@@ -189,11 +194,9 @@ private static function select(ClientState $multi, float $timeout): int
189
194
190
195
private static function generateResponse (Request $ request , AmpClientState $ multi , string $ id , array &$ info , array &$ headers , CancellationTokenSource $ canceller , array &$ options , \Closure $ onProgress , &$ handle , ?LoggerInterface $ logger )
191
196
{
192
- $ activity = &$ multi ->handlesActivity ;
193
-
194
- $ request ->setInformationalResponseHandler (static function (Response $ response ) use (&$ activity , $ id , &$ info , &$ headers ) {
197
+ $ request ->setInformationalResponseHandler (static function (Response $ response ) use ($ multi , $ id , &$ info , &$ headers ) {
195
198
self ::addResponseHeaders ($ response , $ info , $ headers );
196
- $ activity [$ id ][] = new InformationalChunk ($ response ->getStatus (), $ response ->getHeaders ());
199
+ $ multi -> handlesActivity [$ id ][] = new InformationalChunk ($ response ->getStatus (), $ response ->getHeaders ());
197
200
self ::stopLoop ();
198
201
});
199
202
@@ -207,11 +210,11 @@ private static function generateResponse(Request $request, AmpClientState $multi
207
210
208
211
$ options = null ;
209
212
210
- $ activity [$ id ][] = new FirstChunk ();
213
+ $ multi -> handlesActivity [$ id ][] = new FirstChunk ();
211
214
212
215
if ('HEAD ' === $ response ->getRequest ()->getMethod () || \in_array ($ info ['http_code ' ], [204 , 304 ], true )) {
213
- $ activity [$ id ][] = null ;
214
- $ activity [$ id ][] = null ;
216
+ $ multi -> handlesActivity [$ id ][] = null ;
217
+ $ multi -> handlesActivity [$ id ][] = null ;
215
218
self ::stopLoop ();
216
219
217
220
return ;
@@ -231,14 +234,14 @@ private static function generateResponse(Request $request, AmpClientState $multi
231
234
}
232
235
233
236
$ info ['size_download ' ] += \strlen ($ data );
234
- $ activity [$ id ][] = $ data ;
237
+ $ multi -> handlesActivity [$ id ][] = $ data ;
235
238
}
236
239
237
- $ activity [$ id ][] = null ;
238
- $ activity [$ id ][] = null ;
240
+ $ multi -> handlesActivity [$ id ][] = null ;
241
+ $ multi -> handlesActivity [$ id ][] = null ;
239
242
} catch (\Throwable $ e ) {
240
- $ activity [$ id ][] = null ;
241
- $ activity [$ id ][] = $ e ;
243
+ $ multi -> handlesActivity [$ id ][] = null ;
244
+ $ multi -> handlesActivity [$ id ][] = $ e ;
242
245
} finally {
243
246
$ info ['download_content_length ' ] = $ info ['size_download ' ];
244
247
}
0 commit comments