是否可以更改事件Request
接收到的对象的标头fetch
?
两次尝试:
修改现有标题:
self.addEventListener('fetch', function (event) { event.request.headers.set("foo", "bar"); event.respondWith(fetch(event.request)); });
失败
Failed to execute 'set' on 'Headers': Headers are immutable
。创建新
Request
对象:self.addEventListener('fetch', function (event) { var req = new Request(event.request, { headers: { "foo": "bar" } }); event.respondWith(fetch(req)); });
失败
Failed to construct 'Request': Cannot construct a Request with a Request whose mode is 'navigate' and a non-empty RequestInit.
(另请参阅如何更改响应的标头?)