Drop browser-specific headers from CORS proxy service

This commit is contained in:
Alex Gleason committed 2026-01-04 14:35:01 -06:00
1 parent 7e755916c0
commit e45f167d2b
1 file changed
+18 -8
+18 -8
View File
@@ -12,16 +12,26 @@ export default {
return new Response(null, {
status: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "*", // Or specify specific headers
"Access-Control-Max-Age": "86400", // Cache preflight for 24 hours
"access-control-allow-origin": "*",
"access-control-allow-methods": "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS",
"access-control-allow-headers": "*", // Or specify specific headers
"access-control-max-age": "86400", // Cache preflight for 24 hours
}
});
}
const headers = new Headers(request.headers);
headers.set('User-Agent', 'Shakespeare Proxy <https://proxy.shakespeare.diy/>');
headers.set('user-agent', 'Shakespeare Proxy <https://proxy.shakespeare.diy/>');
// Remove forbidden browser headers that cause issues with some services
headers.delete('origin');
headers.delete('referer');
for (const header of headers.keys()) {
if (header.startsWith('sec-')) {
headers.delete(header);
}
}
const targetResponse = await fetch(target, {
method: request.method,
@@ -31,9 +41,9 @@ export default {
const response = new Response(targetResponse.body, targetResponse);
response.headers.set("Access-Control-Allow-Origin", "*");
response.headers.set("Access-Control-Allow-Methods", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS");
response.headers.set("Access-Control-Allow-Headers", "*");
response.headers.set("access-control-allow-origin", "*");
response.headers.set("access-control-allow-methods", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS");
response.headers.set("access-control-allow-headers", "*");
return response;
}