trying replicate logic to get 304 if file was not changed, seems like I need two important headers etag and last-modified, for last-modified seems like I need to save it somewhere in KV store, but etag I can calculate, but seems like cloudflare filtering it out. to be 100% sure I created rule with disabled apps, performance and security. but still no luck, in wrangler preview --watch it shows this header.
import CryptoJS from 'crypto-js'
let response = await getAssetFromKV(event, options)
var md5Hash = CryptoJS.MD5(response.body);
response.headers.set('etag', md5Hash.toString())
Are you trying to replicate 304 from customer to CF, or CF to origin?
I’d try to set ETag and last-modified before the object gets put into KV (via fetch or api), then you will need to implement the condition check on the request.
Will try to set it earlier, thank you for advice. But seems like CF just blocking it (I have another subdomain which just proxying to GCP bucket and it shows etag and last-modified fine).
And thank you for web-crypto will use it instead of crypto-js.
In this particular case origin is a cloudflare KV store, and it doesn’t have etag or last-modified at list etag I can generate, for last-modified I need get it from somewhere probably other KV namespace or save it as part of the value or part of the key. But I can’t see locally generated etag in the output.