Last active
March 25, 2021 14:22
-
-
Save simonhearne/2715250eaccb911ebfff9e2315b2ffee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HEADERS = [ | |
"content-security-policy-report-only", | |
"content-security-policy", | |
"feature-policy", | |
"nel", | |
"report-to", | |
"accept-ch", | |
"referrer-policy", | |
"strict-transport-security", | |
"link" | |
] | |
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}) | |
/** | |
* Respond to the request | |
* @param {Request} request | |
*/ | |
async function handleRequest(request) { | |
let response = await fetch(request.url) | |
let ct = response.headers.get('content-type') | |
if (typeof(ct) == "string" && !ct.includes("text/html")) { | |
response = new Response(response.body,response) | |
HEADERS.map(h => response.headers.delete(h)) | |
} | |
return response | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment