Skip to content

[HttpClient] Make CachingHttpClient compatible with RFC 9111 #59576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 53 commits into
base: 7.4
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
867ee2a
[HttpClient] Add an RFC 9111 compliant client
Lctrs Jan 21, 2025
d8b4992
rename and doc
Lctrs Jan 22, 2025
492b4ab
remove configurable status codes and methods + doc constructor
Lctrs Jan 22, 2025
4dc0157
phpdoc
Lctrs Jan 22, 2025
5462d60
into cachinghttpclient with bc layer
Lctrs Jan 22, 2025
ea6004f
cs
Lctrs Jan 22, 2025
6a2ee73
encode vary field value to avoid collision
Lctrs Jan 22, 2025
dc8069f
require-dev symfony/cache
Lctrs Jan 22, 2025
c06169d
fixing legacy tests
Lctrs Jan 22, 2025
5339c8f
fix legacy tests 2
Lctrs Feb 18, 2025
033f9d8
throw exception when chunk cache item not found
Lctrs Feb 18, 2025
ffedf61
fix check if response is cacheable
Lctrs Feb 18, 2025
c5b0404
more fixes and tests
Lctrs Feb 18, 2025
71f2e3f
cs fixes
Lctrs Feb 18, 2025
54e9fb2
replace ttl by maxTtl (should be clearer) + add missing docs + fix tests
Lctrs Feb 18, 2025
4079e2e
fix lowest tests
Lctrs Feb 18, 2025
22d5691
add changelogs
Lctrs Feb 18, 2025
fb273c9
own cache pool
Lctrs Feb 19, 2025
061118e
added -> add
Lctrs Feb 19, 2025
9c7fe49
$store -> $cache
Lctrs Feb 19, 2025
59cbd40
private legacy
Lctrs Feb 19, 2025
288a2a2
cleanup phpdocs
Lctrs Feb 19, 2025
04439cd
freshness enum
Lctrs Feb 19, 2025
aeddd21
fix stream issues
Lctrs Feb 19, 2025
ea96bf2
more phpdoc fix
Lctrs Feb 19, 2025
a2969ba
cs fix
Lctrs Feb 19, 2025
a52a36b
fix cache definition
Lctrs Feb 20, 2025
47d5422
put caching client between retry and throttling and invalidate cache …
Lctrs Feb 20, 2025
03b782a
also clock mock symfony cache namespace
Lctrs Feb 20, 2025
c949f8a
bcb: also return async response
Lctrs Feb 20, 2025
7f888ac
fix stream and add tests
Lctrs Feb 20, 2025
e6b3756
extend TransportException
Lctrs Feb 21, 2025
e5260d3
tests: in memory cache adapter
Lctrs Feb 21, 2025
454339a
order UPGRADE-7.3.md
Lctrs Feb 28, 2025
df72186
ensure positive integer for max_ttl option
Lctrs Feb 28, 2025
1ab157d
reword CHANGELOG.md
Lctrs Feb 28, 2025
6d4f0d6
remove empty() usage
Lctrs Feb 28, 2025
1b0a30a
evaluateCachedFreshness -> evaluateCacheFreshness
Lctrs Feb 28, 2025
73311bc
remove dev deps on symfony/filesystem
Lctrs Feb 28, 2025
6b1dfda
add more tests
Lctrs Mar 12, 2025
463b71b
vary asterisk prevents caching
Lctrs Mar 12, 2025
0ebc780
exclude non cacheable headers from cache
Lctrs Mar 12, 2025
d1886eb
remove wrongly cacheable status codes
Lctrs Mar 12, 2025
e15142c
implement heuristic caching
Lctrs Mar 12, 2025
bb9b0ba
Update src/Symfony/Component/HttpClient/CachingHttpClient.php
Lctrs Mar 31, 2025
342fedc
Update src/Symfony/Component/HttpClient/CachingHttpClient.php
Lctrs Mar 31, 2025
e16d16f
Update src/Symfony/Component/HttpClient/CachingHttpClient.php
Lctrs Mar 31, 2025
bf285c0
Update src/Symfony/Component/HttpClient/CachingHttpClient.php
Lctrs Mar 31, 2025
8c9871d
switch to a sha256 based hash
Lctrs Mar 31, 2025
54b9fde
turn some vars by ref to static ones
Lctrs Mar 31, 2025
4c1a097
cs
Lctrs Mar 31, 2025
df3f803
more static methods
Lctrs Mar 31, 2025
7c66ffd
switch to TagAwareCacheInterface
Lctrs Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup phpdocs
  • Loading branch information
Lctrs committed Apr 16, 2025
commit 288a2a26022d59bd14ba86d887b8f79ec8575a1c
29 changes: 7 additions & 22 deletions src/Symfony/Component/HttpClient/CachingHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private function buildVariantKey(array $normalizedHeaders, array $varyFields): s
* Parse the Cache-Control header and return an array of directive names as keys
* and their values as values, or true if the directive has no value.
*
* @param string[] $header the Cache-Control header as an array of strings
* @param array<string, string|string[]> $header the Cache-Control header as an array of strings
*
* @return array<string, string|true> the parsed Cache-Control directives
*/
Expand All @@ -474,15 +474,9 @@ private function parseCacheControlHeader(array $header): array
* Evaluates the freshness of a cached response based on its headers and expiration time.
*
* This method determines the state of the cached response by analyzing the Cache-Control
* directives and the expiration timestamp. It returns one of the following states:
* - 'fresh': if the cached response is still valid or has no expiration.
* - 'must-revalidate': if the response must be revalidated before use.
* - 'stale-but-usable': if the response is stale but can be used in case of errors.
* - 'stale': if the cached response is no longer valid or usable.
* directives and the expiration timestamp.
*
* @param array $data the cached response data, including headers and expiration time
*
* @return string the freshness status of the cached response
* @param array{headers: array<string, string[]>, expires_at: int|null} $data the cached response data, including headers and expiration time
*/
private function evaluateCachedFreshness(array $data): string
{
Expand Down Expand Up @@ -598,12 +592,9 @@ private function calculateExpiresAt(?int $maxAge): ?int
* This function will return true if the server response can be cached,
* false otherwise.
*
* @param int $statusCode the HTTP status code of the response
* @param array<string, string|string[]> $requestHeaders the HTTP request headers
* @param array<string, string|string[]> $responseHeaders the HTTP response headers
* @param array<string, string|true> $cacheControl an array of parsed Cache-Control directives
*
* @return bool true if the response is cacheable, false otherwise
* @param array<string, string|string[]> $requestHeaders
* @param array<string, string|string[]> $responseHeaders
* @param array<string, string|true> $cacheControl
*/
private function isServerResponseCacheable(int $statusCode, array $requestHeaders, array $responseHeaders, array $cacheControl): bool
{
Expand Down Expand Up @@ -659,13 +650,7 @@ private function hasExplicitExpiration(array $headers, array $cacheControl): boo
* response headers and content. The constructed MockResponse is then
* returned.
*
* @param string $key the cache key for the response
* @param array $cachedData the cached data for the response
* @param string $method the original request method
* @param string $url the original request URL
* @param array $options the original request options
*
* @return MockResponse the constructed MockResponse object
* @param array{chunks_count: int, status_code: int, initial_age: int, headers: array<string, string|string[]>, stored_at: int} $cachedData
*/
private function createResponseFromCache(string $key, array $cachedData, string $method, string $url, array $options): MockResponse
{
Expand Down