In this example we'll show you how to you add additional headers to your request such as additional cookies.
Create Script
Route: cookie-test
Script contents:
addEventListener("fetch", event => {
event.respondWith(fetchAndApply(event.request));
});
async function fetchAndApply(request) {
const response = await fetch(request);
const modifiedHeaders = new Headers(response.headers);
modifiedHeaders.append("Set-Cookie", "Value 1");
modifiedHeaders.append("Set-Cookie", "Value 2");
const init = {
status: response.status,
statusText: response.statusText,
headers: modifiedHeaders
};
const modifiedResponse = new Response(response.body, init);
return modifiedResponse;
}
Accessing your Script
Once the above has been created, you can access your script using any of the delivery domains on your account. In my example, I can access this script with https://sitehash.stackpathcdn.com/cookie-test