Skip to content

Commit 2350540

Browse files
committed
remove support for StoreInterface as the HTTP client cache
1 parent 6fb186d commit 2350540

File tree

3 files changed

+2
-198
lines changed

3 files changed

+2
-198
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
8.0
55
---
66

7+
* Remove support for passing an instance of `StoreInterface` as `$cache` argument to `CachingHttpClient` constructor, use a `TagAwareCacheInterface` instead
78
* Remove support for amphp/http-client < 5
89
* Remove setLogger() methods on decorators; configure the logger on the wrapped client directly instead
910

CachingHttpClient.php

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
use Symfony\Component\HttpClient\Response\AsyncResponse;
1919
use Symfony\Component\HttpClient\Response\MockResponse;
2020
use Symfony\Component\HttpClient\Response\ResponseStream;
21-
use Symfony\Component\HttpFoundation\Request;
22-
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
23-
use Symfony\Component\HttpKernel\HttpCache\StoreInterface;
24-
use Symfony\Component\HttpKernel\HttpClientKernel;
2521
use Symfony\Contracts\Cache\ItemInterface;
2622
use Symfony\Contracts\Cache\TagAwareCacheInterface;
2723
use Symfony\Contracts\HttpClient\ChunkInterface;
@@ -96,7 +92,6 @@ class CachingHttpClient implements HttpClientInterface, ResetInterface
9692
*/
9793
private const MAX_HEURISTIC_FRESHNESS_TTL = 86400;
9894

99-
private TagAwareCacheInterface|HttpCache $cache;
10095
private array $defaultOptions = self::OPTIONS_DEFAULTS;
10196

10297
/**
@@ -109,46 +104,18 @@ class CachingHttpClient implements HttpClientInterface, ResetInterface
109104
*/
110105
public function __construct(
111106
private HttpClientInterface $client,
112-
TagAwareCacheInterface|StoreInterface $cache,
107+
private readonly TagAwareCacheInterface $cache,
113108
array $defaultOptions = [],
114109
private readonly bool $sharedCache = true,
115110
private readonly ?int $maxTtl = null,
116111
) {
117-
if ($cache instanceof StoreInterface) {
118-
trigger_deprecation('symfony/http-client', '7.4', 'Passing a "%s" as constructor\'s 2nd argument of "%s" is deprecated, "%s" expected.', StoreInterface::class, __CLASS__, TagAwareCacheInterface::class);
119-
120-
if (!class_exists(HttpClientKernel::class)) {
121-
throw new \LogicException(\sprintf('Using "%s" requires the HttpKernel component, try running "composer require symfony/http-kernel".', __CLASS__));
122-
}
123-
124-
$kernel = new HttpClientKernel($client);
125-
$this->cache = new HttpCache($kernel, $cache, null, $defaultOptions);
126-
127-
unset($defaultOptions['debug']);
128-
unset($defaultOptions['default_ttl']);
129-
unset($defaultOptions['private_headers']);
130-
unset($defaultOptions['skip_response_headers']);
131-
unset($defaultOptions['allow_reload']);
132-
unset($defaultOptions['allow_revalidate']);
133-
unset($defaultOptions['stale_while_revalidate']);
134-
unset($defaultOptions['stale_if_error']);
135-
unset($defaultOptions['trace_level']);
136-
unset($defaultOptions['trace_header']);
137-
} else {
138-
$this->cache = $cache;
139-
}
140-
141112
if ($defaultOptions) {
142113
[, $this->defaultOptions] = self::prepareRequest(null, null, $defaultOptions, $this->defaultOptions);
143114
}
144115
}
145116

146117
public function request(string $method, string $url, array $options = []): ResponseInterface
147118
{
148-
if ($this->cache instanceof HttpCache) {
149-
return $this->legacyRequest($method, $url, $options);
150-
}
151-
152119
[$fullUrl, $options] = self::prepareRequest($method, $url, $options, $this->defaultOptions);
153120

154121
$fullUrl = implode('', $fullUrl);
@@ -424,46 +391,6 @@ public function stream(ResponseInterface|iterable $responses, ?float $timeout =
424391
})());
425392
}
426393

427-
private function legacyRequest(string $method, string $url, array $options = []): ResponseInterface
428-
{
429-
[$url, $options] = self::prepareRequest($method, $url, $options, $this->defaultOptions, true);
430-
$url = implode('', $url);
431-
432-
if (!empty($options['body']) || !empty($options['extra']['no_cache']) || !\in_array($method, ['GET', 'HEAD', 'OPTIONS'], true)) {
433-
return new AsyncResponse($this->client, $method, $url, $options);
434-
}
435-
436-
$request = Request::create($url, $method);
437-
$request->attributes->set('http_client_options', $options);
438-
439-
foreach ($options['normalized_headers'] as $name => $values) {
440-
if ('cookie' !== $name) {
441-
foreach ($values as $value) {
442-
$request->headers->set($name, substr($value, 2 + \strlen($name)), false);
443-
}
444-
445-
continue;
446-
}
447-
448-
foreach ($values as $cookies) {
449-
foreach (explode('; ', substr($cookies, \strlen('Cookie: '))) as $cookie) {
450-
if ('' !== $cookie) {
451-
$cookie = explode('=', $cookie, 2);
452-
$request->cookies->set($cookie[0], $cookie[1] ?? '');
453-
}
454-
}
455-
}
456-
}
457-
458-
$response = $this->cache->handle($request);
459-
$response = new MockResponse($response->getContent(), [
460-
'http_code' => $response->getStatusCode(),
461-
'response_headers' => $response->headers->allPreserveCase(),
462-
]);
463-
464-
return MockResponse::fromRequest($method, $url, $options, $response);
465-
}
466-
467394
private static function hash(string $toHash): string
468395
{
469396
return str_replace('/', '_', base64_encode(hash('sha256', $toHash, true)));

Tests/LegacyCachingHttpClientTest.php

Lines changed: 0 additions & 124 deletions
This file was deleted.

0 commit comments

Comments
 (0)