Closed Bug 1890189 Opened 1 year ago Closed 10 months ago

Only lowercase directives are honored for Cache-Control header

Categories

(Core :: Networking: Cache, defect, P2)

Firefox 123
defect
Points:
1

Tracking

()

RESOLVED FIXED
130 Branch
Tracking Status
firefox130 --- fixed

People

(Reporter: mail, Assigned: smayya)

References

(Blocks 1 open bug)

Details

(Whiteboard: [necko-triaged][necko-priority-queue])

Attachments

(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0

Steps to reproduce:

I've been developing a web application where the framework generates HTTP response headers as follows for static resources to ensure ETag is honored:

cache-control: No-Cache
last-modified: Sat, 24 Feb 2024 12:42:28 GMT
etag: "12787-1708778548"

In Chromium, the cache-control directive is honored and I can observe a request always being made to determine whether the resource is still cached or not. In Firefox however, the default heuristic caching behavior still applies and requests are not always being made. I managed to work around this by instructing the framework to use lowercase directives as follows:

cache-control: no-cache

After this change, the caching behavior in Firefox is the same as in Chromium.

This strikes me as unexpected, given the documentation on MDN at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control:

Caching directives are case-insensitive. However, lowercase is recommended because some implementations do not recognize uppercase directives.

Actual results:

Caching directive is only honored when using a lowercase directive:

cache-control: no-cache

Expected results:

Caching directive is honored no matter the casing. Therefore, both

cache-control: no-cache

and

cache-control: No-Cache

should result in the same caching behavior, consistent with MDN documentation of directives being case-insensitive.

Component: Untriaged → Networking: Cache
Product: Firefox → Core

Thank you for the bug report.
This is definitely something we should rectify, and I think it should be easy to do so.
We need to change CacheControlParser to use custom tokens like we do here

Severity: -- → S3
Priority: -- → P2
Whiteboard: [necko-triaged][necko-priority-new]
Whiteboard: [necko-triaged][necko-priority-new] → [necko-triaged][necko-priority-next]

This might actually affect performance - when we don't cache things properly.

Blocks: necko-perf
Points: --- → 1
Whiteboard: [necko-triaged][necko-priority-next] → [necko-triaged][necko-priority-queue]

(In reply to Valentin Gosu [:valentin] (he/him) from comment #1)

Thank you for the bug report.
This is definitely something we should rectify, and I think it should be easy to do so.
We need to change CacheControlParser to use custom tokens like we do here

Instead of using CheckWord, we need to add the custom tokens and check them like this instead.

Assignee: nobody → smayya

Depends on D216486

Attachment #9412618 - Attachment description: WIP: Bug 1890189: Add test to verify cache-control header parising is case-insensitive. r=#necko → Bug 1890189: Add test to verify cache-control header parising is case-insensitive. r=#necko
Attachment #9412619 - Attachment description: WIP: Bug 1890189: make cache control parsing case insensitive → Bug 1890189: make cache control parsing case insensitive. r=#necko
Pushed by smayya@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2767e60da4f2 Add test to verify cache-control header parising is case-insensitive. r=necko-reviewers,kershaw https://hg.mozilla.org/integration/autoland/rev/ae2a7f70cc15 make cache control parsing case insensitive. r=necko-reviewers,kershaw
Status: UNCONFIRMED → RESOLVED
Closed: 10 months ago
Resolution: --- → FIXED
Target Milestone: --- → 130 Branch
Attachment #9412619 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: