Skip to content

Commit c81927d

Browse files
committed
disable range support again + other reviews
1 parent 67f2b47 commit c81927d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/Symfony/Component/HttpClient/CHANGELOG.md

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

77
* Deprecate using amphp/http-client < 5
88
* Add RFC 9111–based caching support to `CachingHttpClient`
9+
* Deprecate passing an instance of `StoreInterface` as `$cache` argument to `CachingHttpClient` constructor
910

1011
7.3
1112
---

src/Symfony/Component/HttpClient/CachingHttpClient.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
* Adds caching on top of an HTTP client (per RFC 9111).
3535
*
3636
* Known omissions / partially supported features per RFC 9111:
37-
* 1. stale-while-revalidate:
37+
* 1. Range requests:
38+
* - All range requests ("partial content") are passed through and never cached.
39+
* 2. stale-while-revalidate:
3840
* - There's no actual "background revalidation" for stale responses, they will
3941
* always be revalidated.
40-
* 2. min-fresh, max-stale, only-if-cached:
42+
* 3. min-fresh, max-stale, only-if-cached:
4143
* - Request directives are not parsed; the client ignores them.
4244
*
4345
* @see https://www.rfc-editor.org/rfc/rfc9111
@@ -78,7 +80,6 @@ class CachingHttpClient implements HttpClientInterface, ResetInterface
7880
'cookie' => true,
7981
'expect' => true,
8082
'host' => true,
81-
'range' => true,
8283
'user-agent' => true,
8384
];
8485
/**
@@ -114,7 +115,7 @@ public function __construct(
114115
private readonly ?int $maxTtl = null,
115116
) {
116117
if ($cache instanceof StoreInterface) {
117-
trigger_deprecation('symfony/http-client', '7.3', 'Passing a "%s" as constructor\'s 2nd argument of "%s" is deprecated, "%s" expected.', StoreInterface::class, __CLASS__, TagAwareCacheInterface::class);
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);
118119

119120
if (!class_exists(HttpClientKernel::class)) {
120121
throw new \LogicException(\sprintf('Using "%s" requires the HttpKernel component, try running "composer require symfony/http-kernel".', __CLASS__));
@@ -157,11 +158,11 @@ public function request(string $method, string $url, array $options = []): Respo
157158
$this->cache->invalidateTags([$fullUrlTag]);
158159
}
159160

160-
if ('' !== $options['body'] || ($options['extra']['no_cache'] ?? false) || !\in_array($method, self::CACHEABLE_METHODS, true)) {
161+
if ('' !== $options['body'] || ($options['extra']['no_cache'] ?? false) || isset($options['normalized_headers']['range']) || !\in_array($method, self::CACHEABLE_METHODS, true)) {
161162
return new AsyncResponse($this->client, $method, $url, $options);
162163
}
163164

164-
$requestHash = self::hash($method.$fullUrl.json_encode(array_intersect_key($options['normalized_headers'], self::RESPONSE_INFLUENCING_HEADERS), \JSON_THROW_ON_ERROR));
165+
$requestHash = self::hash($method.$fullUrl.serialize(array_intersect_key($options['normalized_headers'], self::RESPONSE_INFLUENCING_HEADERS)));
165166
$varyKey = "vary_{$requestHash}";
166167
$varyFields = $this->cache->get($varyKey, static function (ItemInterface $item, bool &$save): array {
167168
$save = false;

0 commit comments

Comments
 (0)