Skip to content

Conversation

pilif
Copy link

@pilif pilif commented Aug 25, 2025

this is an updated version of #128, rebased on top of current HEAD and with a fix to the test to reflect the new reality (which is what #128 was waiting on for 2 years).

This is super useful when talking to a server outside of the caller's control if a stale response is always preferable to no response and if the server is living in the past and providing no useful cache validation feature.

In this case, a stale response can still be served from cache while a full download happens in the background

Due to its name, the stale-while-revalidate Cache-Control extension
might suggest that it only applies to revalidation requests. However,
looking at https://tools.ietf.org/html/rfc5861#section-3...

> The stale-while-revalidate Cache-Control Extension
> When present in an HTTP response, the stale-while-revalidate
> Cache-Control extension indicates that caches MAY serve the
> response in which it appears after it becomes stale, up to the
> indicated number of seconds.
> stale-while-revalidate = "stale-while-revalidate" "=" delta-seconds
> If a cached response is served stale due to the presence of this
> extension, the cache SHOULD attempt to revalidate it while still
> serving stale responses (i.e., without blocking).

There is no reason why a cache should not also return a stale response
while a complete re-fetch happens in the background (just what would
happen if validation fails).

This makes a difference if, for example, a resource has
`Cache-Control: public, max-age=30, stale-while-revalidate=30` set and
no additional Last-Modified or ETag headers.

Co-Authored-By: Philip Hofstetter <[email protected]
@pilif pilif force-pushed the revalidate-without-validator branch from a7d25e6 to 9d515ed Compare August 25, 2025 12:54
@pilif
Copy link
Author

pilif commented Aug 26, 2025

the test is failing due to an interaction between https://datatracker.ietf.org/doc/html/rfc5861 an stale-while-revalidate and rfc 9111 https://httpwg.org/specs/rfc9111.html#cache-request-directive.max-stale max-stale.

The code is currently re-requesting the resource because it doesn't see the max-stale directive. However from an additional reading of rfc5861 I come to the conclusion that we should respond with the stale response even though the max-stale header is missing because stale-while-revalidate reads to me as giving the permission to serve a stale response in this case no matter what the client wants.

I will make the required adjustments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants