Skip to content

Instantly share code, notes, and snippets.

@simonhearne
Last active March 25, 2021 14:22
Show Gist options
  • Save simonhearne/2715250eaccb911ebfff9e2315b2ffee to your computer and use it in GitHub Desktop.
Save simonhearne/2715250eaccb911ebfff9e2315b2ffee to your computer and use it in GitHub Desktop.
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