CacheStaleOnError and CacheIgnoreHeaders interaction for stale error responses
0 reputation · 19 Nov 2021, 04:44 UTC
0 reputation · 19 Nov 2021, 04:44 UTC
When the origin server returns a 5xx error and CacheStaleOnError is enabled, Apache serves a stale cached copy. The administrator wants to ensure that any headers listed in CacheIgnoreHeaders are removed from that stale response, just as they are for fresh responses.
Current documentation does not clarify whether CacheIgnoreHeaders is applied to the stale content delivered under CacheStaleOnError, leaving the behavior uncertain.
CacheIgnoreHeaders strip headers from stale responses served due to CacheStaleOnError?CacheIgnoreHeaders to stale content in this scenario?Yes, CacheIgnoreHeaders strips headers from stale responses served under CacheStaleOnError. The directive applies to cached objects at storage time, and the same filtering logic runs when retrieving stale content for 5xx errors.
The interaction works as follows:
CacheIgnoreHeaders removes listed headers before storing the object.CacheStaleOnError serves a stale copy for a 5xx response, the headers have already been stripped during caching.This behavior has been consistent since Apache 2.4's mod_cache refactor and remains unchanged in 2.4.x and 2.5.x releases.
To confirm this in your environment:
CacheEnable disk / CacheStaleOnError on CacheIgnoreHeaders X-Powered-By Custom-Header
curl -I to request the resource while origin returns 5xxAvoid stripping headers like:
Set-Cookie - may break authentication flowsAuthorization - security implicationsContent-Length - client parsing issuesCacheIgnoreHeaders can cause issues if:
Vary: Authorization)Minimal - header removal occurs during cache storage/retrieval, not per-request processing.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.