Skip to content

Instantly share code, notes, and snippets.

@technicool
Created February 28, 2020 16:42
Show Gist options
  • Save technicool/b009f822666039c5ac71cb8d9375f611 to your computer and use it in GitHub Desktop.
Save technicool/b009f822666039c5ac71cb8d9375f611 to your computer and use it in GitHub Desktop.
StackPath script to show request headers, including GEO information
let reqCount = 0;
// sample script
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
reqCount += 1;
const headers = new Headers();
//Set the proper content-type so the browser understands what we're sending back
headers.set("content-type", ["text/html; charset=UTF-8"]);
let fggg = await fetch("https://unwritten.media");
//Create a response with the robots.txt data we want
let body = `<h1>Unwritten Media CDN #${reqCount}</h1><p>We do love our ${request['headers'].get('x-sp-client-geo-city')} customers.<hr/><code>${JSON.stringify(request)}</code><hr/><code>${JSON.stringify(fggg.headers)}</code>`;
return new Response(body, {
status: "200",
headers
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment