mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
Drop browser-specific headers from CORS proxy service
This commit is contained in:
1 file changed
+18
-8
+18
-8
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user