12
12
namespace Symfony \Component \HttpClient ;
13
13
14
14
use Symfony \Component \Cache \Adapter \TagAwareAdapterInterface ;
15
+ use Symfony \Component \HttpClient \Chunk \ErrorChunk ;
15
16
use Symfony \Component \HttpClient \Exception \ChunkCacheItemNotFoundException ;
16
17
use Symfony \Component \HttpClient \Response \AsyncContext ;
17
18
use Symfony \Component \HttpClient \Response \AsyncResponse ;
@@ -149,7 +150,7 @@ public function request(string $method, string $url, array $options = []): Respo
149
150
// consistent expiration time for all items
150
151
$ expiresAt = null === $ this ->ttl
151
152
? null
152
- : new \DateTimeImmutable ( " + { $ this ->ttl } seconds " );
153
+ : \DateTimeImmutable:: createFromFormat ( ' U ' , time () + $ this ->ttl );
153
154
154
155
return new AsyncResponse (
155
156
$ this ->client ,
@@ -173,13 +174,17 @@ function (ChunkInterface $chunk, AsyncContext $context) use (
173
174
): \Generator {
174
175
if (null !== $ chunk ->getError () || $ chunk ->isTimeout ()) {
175
176
if ('stale-but-usable ' === $ freshness ) {
177
+ // avoid throwing exception in ErrorChunk#__destruct()
178
+ $ chunk instanceof ErrorChunk && $ chunk ->didThrow (true );
176
179
$ context ->passthru ();
177
180
$ context ->replaceResponse ($ this ->createResponseFromCache ($ metadataKey , $ cachedData , $ method , $ url , $ options ));
178
181
179
182
return ;
180
183
}
181
184
182
185
if ('must-revalidate ' === $ freshness ) {
186
+ // avoid throwing exception in ErrorChunk#__destruct()
187
+ $ chunk instanceof ErrorChunk && $ chunk ->didThrow (true );
183
188
$ context ->passthru ();
184
189
$ context ->replaceResponse ($ this ->createGatewayTimeoutResponse ($ method , $ url , $ options ));
185
190
@@ -419,7 +424,7 @@ private function buildVariantKey(array $normalizedHeaders, array $varyFields): s
419
424
} else {
420
425
$ joined = \is_array ($ normalizedHeaders [$ lower ])
421
426
? implode (', ' , $ normalizedHeaders [$ lower ])
422
- : ( string ) $ normalizedHeaders [$ lower ];
427
+ : $ normalizedHeaders [$ lower ];
423
428
$ parts [] = $ field .'= ' .rawurlencode ($ joined );
424
429
}
425
430
}
0 commit comments