Why is URL empty for request from kv-asset-handler and do header changes work with wrangler locally?

I am trying to apply headers based on the url, but testing locally, the response url is always empty. I'm also wondering if its worth changing the response headers at all, because would that really change the way the assets are cached on the server or would it just affect the HTML?
No description
4 Replies
Ed
EdOP3mo ago
Does kv-asset-handler respect cache-control headers added to the response? Or are they set somewhere else.
Ed
EdOP3mo ago
So this is working but does applying the headers to the response based on the original request sent to KV actually affect the caching behavior of said KV or is it just applied to the request with no considerable effect? Furthermore, is there a better way to do this?
No description
James
James3mo ago
For the most compatibility, you'll want to set the browserTTL and edgeTTL options: https://github.com/cloudflare/workers-sdk/blob/c4f0d9e01ef333f5882096ad1e0f37e0911089a7/packages/kv-asset-handler/src/index.ts#L17 You can conditionally change the options you pass to kv-asset-handler before calling getAssetFromKV, like your assets check And the Response is constructed manually using new Response() so it's not going to have a valid url property on it - that's expected. Checking the request is how you'll want to do those conditions, like your most recent example.
Ed
EdOP3mo ago
I see, that makes more sense now, thank you!
Want results from more Discord servers?
Add your server