Is it possible to change the headers of the Response object returned by fetch() ?
Suppose I want to convert a response through resFn :
self.addEventListener('fetch', function (event) { event.respondWith(fetch(event.request).then(resFn)); });
What should resFn() look like? One try:
function resFn(res) { res = res.clone(); res.headers.set("foo", "bar"); return res; }
Failure with TypeError: Failed to execute 'set' on 'Headers': Headers are immutable .
(A separate question and answer explains how to change the request headers . Given that Request and Response objects are surprisingly different (different properties, and their constructors take different arguments), does the same decision?)
javascript service-worker
mjs
source share