Skip to content

Commit

Permalink
fix(Example): Apparently response headers are immutable. Closes [#27] (
Browse files Browse the repository at this point in the history
  • Loading branch information
gja committed Jan 27, 2019
1 parent 49fae52 commit 31cb10b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions examples/unit-test-a-worker/worker.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
// Add any more global vars (like Request, Response) to the below list as they are used
/* global addEventListener fetch Response Headers */

addEventListener("fetch", e => {
e.respondWith(fetchAndAddHeader(e.request));
});

async function fetchAndAddHeader(request) {
const response = await fetch(request);

const headers = new Headers(response.headers);

if (response.status === 200) {
response.headers.set("Foo", "Bar");
headers.set("Foo", "Bar");
} else {
response.headers.set("Foo", "Not Bar");
headers.set("Foo", "Not Bar");
}

return response;
return new Response(response.body, {
headers: headers,
status: response.status,
statusText: response.statusText,
});
}

0 comments on commit 31cb10b

Please sign in to comment.