Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 295994

Introduce "Vary" page cache response policy

$
0
0

Problem/Motivation

If you want to return different responses for the same request, depending on values of HTTP headers, resulting response cannot be cached neither in internal nor in external response-level cache.

Examples of such requests:

- Browser language negotiation (#2430335: Browser language detection is not cache aware) should have different results depending on visitor's language preferences, sent in "Accept-Language" header.
- Site needs to display local sales office to people depending on their originating country. Many CDN providers (Cloudflare, Akamai etc.) sent this information in HTTP header.

The only existing way to return headers-dependent response is to mark it non-cacheable (use KillSwitch policy). That happens because cacheability metadata that contains "header" context (implemented in HeadersCacheContext class) is only stored in renderable arrays, but not exposed to reverse proxies (or internal page context).

Proposed resolution

Introduce new Vary page response policy, that will tell reverse proxies how to properly cache returned responses. This proposal was originally raised in #2430335: Browser language detection is not cache aware, but moved to the new issue, as it solves a bigger problem.

@catch in https://www.drupal.org/project/drupal/issues/2430335#comment-12842970 argues against usage of vary header in core itself, but with all respect, I cannot agree - Vary is the standard HTTP way of informing proxies about cache contexts of the origin server, especially when the response varies depending on one or more HTTP headers. Vary header is here exactly for this purpose, so it seems natural to use it.

Remaining tasks

- Rewrite the patch from https://www.drupal.org/project/drupal/issues/2430335#comment-12840473, leaving only the part that introduces new response policy (and it's test)
- Modify the patch in #2430335: Browser language detection is not cache aware to only contain changes needed for browser language negotiation.

User interface changes

- No UI changes

API changes

- New page_cache_vary service that triggers adding Vary header

Release notes snippet

Issue priority

Major since it unblocks major bug #2430335: Browser language detection is not cache aware


Viewing all articles
Browse latest Browse all 295994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>