Opened 2 years ago

Last modified 23 months ago

#27225 assigned Bug

Cache-Control's max-age doesn't match Expires for responses taken from cache

Reported by: Rinat Khabibiev Owned by: Rinat Khabibiev
Component: HTTP handling Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


When fetching response from the cache, 'Cache-Control' contains 'max-age' corresponding to the moment of original response generation time, thus for another time it usually doesn't match 'Expires' value.

Change History (9)

comment:1 Changed 2 years ago by Rinat Khabibiev

Status: newassigned

comment:2 Changed 2 years ago by Tim Graham

I'm not sure if the proposed behavior is correct. From RC2616 sec14.9.3 (which I only skimmed, so please provide another reference if it's wrong):

If a response includes both an Expires header and a max-age directive, the max-age directive overrides the Expires header, even if the Expires header is more restrictive.

I think I understand the idea behind the PR, however, it seems to treat the Expires as authoritative rather than max-age.

comment:3 Changed 2 years ago by Rinat Khabibiev

Exactly, and that's why it is a bug.

It would be correct behavior if response include Date header corresponding to original response generation time. But I'm not sure

comment:4 Changed 2 years ago by Rinat Khabibiev

RFC7234 says about Age header which indicates age of the cache, so instead of Cache-Control's max-age regeneration it is possible to set Age. Also there is good visual explanation how browser cache should work:

Last edited 2 years ago by Rinat Khabibiev (previous) (diff)

comment:5 Changed 2 years ago by Tim Graham

My understanding is that the current pull request fix isn't correct then, right?

comment:6 Changed 2 years ago by Rinat Khabibiev

Yes, it isn't. I'm going to fix it soon.

comment:7 Changed 2 years ago by Rinat Khabibiev

Ready. Changed behavior: FetchFromCacheMiddleware sets Age header now.

comment:8 Changed 2 years ago by Tim Graham

Has patch: set
Triage Stage: UnreviewedAccepted

comment:9 Changed 23 months ago by Tim Graham

Patch needs improvement: set

I left comments for improvement on the PR. Please uncheck "Patch needs improvement" after updating it.

Note: See TracTickets for help on using tickets.
Back to Top