Browse Source

fix(proxy): remove prohibited CF-* headers to prevent Cloudflare Error 1000

master
mortezaei 4 days ago
parent
commit
d351f32b25
  1. 23
      src/app/api/proxy/route.ts

23
src/app/api/proxy/route.ts

@ -17,14 +17,6 @@ const REQUEST_HEADERS_TO_FORWARD = [
"x-csrftoken", "x-csrftoken",
"x-requested-with", "x-requested-with",
"x-xsrf-token", "x-xsrf-token",
"cf-connecting-ip",
"cf-ipcountry",
"cf-ray",
"cf-visitor",
"x-real-ip",
"x-forwarded-for",
"x-forwarded-proto",
"x-forwarded-host",
]; ];
const RESPONSE_HEADERS_TO_DROP = [ const RESPONSE_HEADERS_TO_DROP = [
@ -174,23 +166,14 @@ function getRequestHeaders(request: NextRequest, targetUrl: URL) {
headers.set("referer", `${targetUrl.origin}/`); headers.set("referer", `${targetUrl.origin}/`);
headers.set("user-agent", "dart:io"); headers.set("user-agent", "dart:io");
// Forward real client IP and Geo headers to Django backend
// Forward standard X-Forwarded-For if client IP is available
const clientIp = const clientIp =
request.headers.get("cf-connecting-ip") || request.headers.get("cf-connecting-ip") ||
request.headers.get("x-real-ip") || request.headers.get("x-real-ip") ||
request.headers.get("x-forwarded-for")?.split(",")[0]?.trim(); request.headers.get("x-forwarded-for")?.split(",")[0]?.trim();
if (clientIp) {
headers.set("cf-connecting-ip", clientIp);
headers.set("x-real-ip", clientIp);
if (!headers.has("x-forwarded-for")) {
headers.set("x-forwarded-for", clientIp);
}
}
const cfCountry = request.headers.get("cf-ipcountry");
if (cfCountry) {
headers.set("cf-ipcountry", cfCountry);
if (clientIp && !headers.has("x-forwarded-for")) {
headers.set("x-forwarded-for", clientIp);
} }
return headers; return headers;

Loading…
Cancel
Save