Skip to content

Commit 5b52dd2

Browse files
committed
more fixes and tests
1 parent 6bbe926 commit 5b52dd2

File tree

3 files changed

+280
-11
lines changed

3 files changed

+280
-11
lines changed

src/Symfony/Component/HttpClient/CachingHttpClient.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpClient;
1313

1414
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;
15+
use Symfony\Component\HttpClient\Chunk\ErrorChunk;
1516
use Symfony\Component\HttpClient\Exception\ChunkCacheItemNotFoundException;
1617
use Symfony\Component\HttpClient\Response\AsyncContext;
1718
use Symfony\Component\HttpClient\Response\AsyncResponse;
@@ -149,7 +150,7 @@ public function request(string $method, string $url, array $options = []): Respo
149150
// consistent expiration time for all items
150151
$expiresAt = null === $this->ttl
151152
? null
152-
: new \DateTimeImmutable("+{$this->ttl} seconds");
153+
: \DateTimeImmutable::createFromFormat('U', time() + $this->ttl);
153154

154155
return new AsyncResponse(
155156
$this->client,
@@ -173,13 +174,17 @@ function (ChunkInterface $chunk, AsyncContext $context) use (
173174
): \Generator {
174175
if (null !== $chunk->getError() || $chunk->isTimeout()) {
175176
if ('stale-but-usable' === $freshness) {
177+
// avoid throwing exception in ErrorChunk#__destruct()
178+
$chunk instanceof ErrorChunk && $chunk->didThrow(true);
176179
$context->passthru();
177180
$context->replaceResponse($this->createResponseFromCache($metadataKey, $cachedData, $method, $url, $options));
178181

179182
return;
180183
}
181184

182185
if ('must-revalidate' === $freshness) {
186+
// avoid throwing exception in ErrorChunk#__destruct()
187+
$chunk instanceof ErrorChunk && $chunk->didThrow(true);
183188
$context->passthru();
184189
$context->replaceResponse($this->createGatewayTimeoutResponse($method, $url, $options));
185190

@@ -419,7 +424,7 @@ private function buildVariantKey(array $normalizedHeaders, array $varyFields): s
419424
} else {
420425
$joined = \is_array($normalizedHeaders[$lower])
421426
? implode(',', $normalizedHeaders[$lower])
422-
: (string) $normalizedHeaders[$lower];
427+
: $normalizedHeaders[$lower];
423428
$parts[] = $field.'='.rawurlencode($joined);
424429
}
425430
}

0 commit comments

Comments
 (0)