Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.