Workers _headers not working
https://developers.cloudflare.com/workers/static-assets/headers/#custom-headers
Can anyone help me understand best practices for getting this to work? I have a _headers file in my public assets root but the file is being served if I hit it over HTTPS and the rules are being disregarded.
I see multiple threads and wondering if there is a workaround. I am trying to set headers on static assets but the rules I set are being disregarded. Is this just a known issue or am I doing something incorrectly?
https://community.cloudflare.com/t/headers-file-on-worker-static-assets-not-working-workers-for-platforms/820474
https://community.cloudflare.com/t/setting-cache-headers-for-static-assets/720802
Cloudflare Docs
Headers
When serving static assets, Workers will attach some headers to the response by default. These are:
5 Replies
What version of wrangler do you have?
Wrangler 4.36.0 in my package.json
I think this GHA is the code that is actually deploying it: https://github.com/nuxt-hub/cli/blob/main/src/utils/deploy.mjs#L227
Which, if I'm understanding it correctly, looks the same as that of wrangler: https://github.com/cloudflare/workers-sdk/blob/446e967ec161a41e4a931855795d6567723fcbdd/packages/wrangler/src/assets.ts#L168
And I don't see any special handling for _headers during upload, but I also don't know the wrangler codebase. Are _headers files treated differently at upload time than other files?
Aha maybe this is it, magic files are not added to the public files manifest:
https://github.com/cloudflare/workers-sdk/blob/main/packages/workers-shared/utils/helpers.ts#L79
But I think this other one is probably doing it
I'm also not aware of how github action workers with Workers Assets. I passed along to the team!
Thank you! Mainly just wondering how the secret sauce is for _headers -- is it hardcoded that the file with that name should always be applied as rules, or does it only get applied in certain cases. Thanks again
It gets put into the metadata in the payload of your upload request (which is why I was asking about the wrangler version).