Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass X-Cors-Headers between the client and the remote #471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/cors-anywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,17 @@ function onProxyResponse(proxy, proxyReq, proxyRes, req, res) {
}
}

let extraHeaders = {}

// Strip cookies
delete proxyRes.headers['set-cookie'];
delete proxyRes.headers['set-cookie2'];
for (let k of ['set-cookie', 'set-cookie2']) {
if (k in proxyRes.headers) {
extraHeaders[k] = proxyRes.headers[k];
delete proxyRes.headers[k];
}
}

proxyRes.headers['x-cors-headers'] = JSON.stringify(extraHeaders);
proxyRes.headers['x-final-url'] = requestState.location.href;
withCORS(proxyRes.headers, req);
return true;
Expand Down Expand Up @@ -392,6 +399,14 @@ function getHandler(options, proxy) {
var isRequestedOverHttps = req.connection.encrypted || /^\s*https/.test(req.headers['x-forwarded-proto']);
var proxyBaseUrl = (isRequestedOverHttps ? 'https://' : 'http://') + req.headers.host;

try {
let extraHeaders = JSON.parse(req.headers['x-cors-headers'] || "{}");
for (let [k, v] of Object.entries(extraHeaders)) {
req.headers[k] = v;
}
delete req.headers['x-cors-headers'];
} catch (e) {}

corsAnywhere.removeHeaders.forEach(function(header) {
delete req.headers[header];
});
Expand Down