Overview
You can use this document to learn how to add additional headers to your request, such as additional cookies.
Before you begin, you must enable serverless scripting for your stack. To learn more, see Enable Serverless Scripting and Create a Script.
View a sample script
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;
}
Access your script
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://sitehash.stackpathcdn.com/cookie-test