Add Headers to a Response
You can use this document to learn how to add additional headers to your request, such as additional cookies.
In the following example, the route is: cookie-test
Review the following sample script:
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;
}
You can access your script with any of the Delivery Domains on your account.
Based on the above example, you can access the script with: https://domain.com/cookie-test
Updated 5 months ago