|
34 | 34 | * Adds caching on top of an HTTP client (per RFC 9111). |
35 | 35 | * |
36 | 36 | * 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: |
38 | 40 | * - There's no actual "background revalidation" for stale responses, they will |
39 | 41 | * always be revalidated. |
40 | | - * 2. min-fresh, max-stale, only-if-cached: |
| 42 | + * 3. min-fresh, max-stale, only-if-cached: |
41 | 43 | * - Request directives are not parsed; the client ignores them. |
42 | 44 | * |
43 | 45 | * @see https://www.rfc-editor.org/rfc/rfc9111 |
@@ -78,7 +80,6 @@ class CachingHttpClient implements HttpClientInterface, ResetInterface |
78 | 80 | 'cookie' => true, |
79 | 81 | 'expect' => true, |
80 | 82 | 'host' => true, |
81 | | - 'range' => true, |
82 | 83 | 'user-agent' => true, |
83 | 84 | ]; |
84 | 85 | /** |
@@ -114,7 +115,7 @@ public function __construct( |
114 | 115 | private readonly ?int $maxTtl = null, |
115 | 116 | ) { |
116 | 117 | 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); |
118 | 119 |
|
119 | 120 | if (!class_exists(HttpClientKernel::class)) { |
120 | 121 | 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 |
157 | 158 | $this->cache->invalidateTags([$fullUrlTag]); |
158 | 159 | } |
159 | 160 |
|
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)) { |
161 | 162 | return new AsyncResponse($this->client, $method, $url, $options); |
162 | 163 | } |
163 | 164 |
|
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))); |
165 | 166 | $varyKey = "vary_{$requestHash}"; |
166 | 167 | $varyFields = $this->cache->get($varyKey, static function (ItemInterface $item, bool &$save): array { |
167 | 168 | $save = false; |
|
0 commit comments