Vary: User-Agent + new UA string (i.e. after update) + HTTP 304 = broken cache

RESOLVED FIXED in mozilla11



Networking: Cache
6 years ago
6 years ago


(Reporter: Doug Wright, Assigned: mayhemer)


Windows 7

Firefox Tracking Flags

(Not tracked)



(1 attachment, 1 obsolete attachment)



6 years ago
For resources that use Vary: User-Agent, the cache stores the UA string that was used in the initial request. When a request is made for that same resource but the UA string has changed since the initial request, Gecko will validate the previously cached data using If-None-Match.

That's fine, except when the server replies with a 304, the cache is apparently not updated with the new UA string and consequently the resource will be continue to be revalidated every single time the browser asks for it which renders the cache largely useless (particularly on a high-latency connection).


0) Enable HTTP logger of your choice

1) Visit
2) Click Home. Again. And Again.
3) Note that the only resource fetched from those clicks is the page itself

4) Change your UA string (e.g. upgrade to new build, or fiddle with about:config)

5) Repeat steps (1) and (2)
6) Note that in addition to the page, requests for the CSS and JS are issued every time.

7) Downgrade to previous build, or revert about:config changes

8) Repeat steps (1) and (2)
9) Note that cache behaves again, and requests for the CSS and JS are not issued.
Honza, can you take a look please?

Comment 2

6 years ago
Created attachment 543762 [details] [diff] [review]

According to RFC 2616, section 13.6: "If the entity-tag of the new response matches that of an existing entry, the new response SHOULD be used to update the header fields of the existing entry, and the result MUST be returned to the client."  This applies to 304 responses.

Code that does this update is in nsHttpChannel::AddCacheEntryHeaders.  We seems to lack call to that method from nsHttpChannel::ProcessNotModified.  The patch adds it, and this also fixes this bug.

Only disadvantage is that we overwrite the response head in cache with the cached one - i.e. identical one (a bit wasting).
Assignee: nobody → honzab.moz
Attachment #543762 - Flags: review?(bzbarsky)

Comment 3

6 years ago
And yes, we should have a test as well.  And I will also push this to try.

Comment 4

6 years ago
Try is green:
Comment on attachment 543762 [details] [diff] [review]

Please add a test.

r=me with that.
Attachment #543762 - Flags: review?(bzbarsky) → review+

Comment 6

6 years ago
If a test is really tricky, can the patch get checked in anyway in the meantime?

Comment 7

6 years ago
The test is probably not that tricky, just no time to write it now.  Anyway, I think it is too late, we have some 4 days to merge to aurora.  I don't think we want to take this change w/o proper testing on the trunk first.

Comment 8

6 years ago
Created attachment 566591 [details] [diff] [review]

Ready to land
Attachment #543762 - Attachment is obsolete: true
Attachment #566591 - Flags: review+

Comment 9

6 years ago
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla11
You need to log in before you can comment on or make changes to this bug.