Skip to content

Commit

Permalink
Remove specific headers for cloudflare to have better cache regularity
Browse files Browse the repository at this point in the history
  • Loading branch information
joelwurtz committed Apr 20, 2021
1 parent 783d5b4 commit 3161383
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ function create_redirectionio_request(request, libredirectionio) {
const redirectionioRequest = new libredirectionio.Request(urlObject.pathname + urlObject.search, urlObject.host, urlObject.protocol.includes('https') ? 'https' : 'http', request.method);

for (const pair of request.headers.entries()) {
// remove cloudflare specific headers
if (pair[0] === "cf-request-id") {
continue;
}

if (pair[0] === "cf-ray") {
continue;
}

if (pair[0] === "cf-visitor") {
continue;
}

redirectionioRequest.add_header(pair[0], pair[1]);
}

Expand All @@ -55,7 +68,7 @@ async function get_action(request, redirectionioRequest, options, libredirection

// Convert to a GET to be able to cache
const cacheKey = new Request(cacheUrl.toString(), {
headers: request.headers,
headers: [],
method: "GET",
});

Expand Down

0 comments on commit 3161383

Please sign in to comment.