Skip to content

Common caching worker not caching requests using HEAD method #18

Description

@alxbridge

It appears that all requests sent using the HEAD method are passed on to the backend servers, which can make a site easy to overload with a flurry of this type of request.

According to Cloudflare's docs,

cache.put will throw an error if:

  • The request passed is a method other than GET.

This is in contrast with Cloudflare's default behaviour for caching HEAD requests:

When you make a HEAD request for a cacheable resource and Cloudflare does not have that resource in the edge cache, a cache miss happens. Cloudflare will send a GET request to your origin, cache the full response and return the response headers only.

To verify this behaviour on a site using the worker, compare the cf-cache-status header returned for a request made with GET:

curl -v [URL] 2>&1 | grep "cf-cache-status"
# < cf-cache-status: HIT - at least from the second request onwards

with the same request made with HEAD:

curl --head -v [URL] 2>&1 | grep "cf-cache-status"
# < cf-cache-status: DYNAMIC - always

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions