I'm currently working on figuring out the age of a cached response by utilizing the date header of the response. I attempted to do this using a plugin that utilizes cachedResponseWillBeUsed
. However, when trying to access cachedResponse.headers
, I am not getting any data. Is this supposed to happen? Code provided below:
const cachedResponsePlugin = {
cachedResponseWillBeUsed: ({ cachedResponse }) => {
let headers = new Headers(cachedResponse.headers);
console.log(cachedResponse.headers); // Empty
headers.set("X-Cached-Response", "true");
return cachedResponse.arrayBuffer().then((buffer) => {
return new Response(buffer, {
status: cachedResponse.status,
statusText: cachedResponse.statusText,
headers,
});
});
},
};