cors-anywhere icon indicating copy to clipboard operation
cors-anywhere copied to clipboard

Adding header in the proxy

Open benzata opened this issue 5 years ago • 7 comments

Is it possible to add your header for GET requests inside the CORS-Anywhere PROXY? Instead of putting in the header of the GET request in the app code? Thank you very much in advance!!

benzata avatar Apr 19 '20 09:04 benzata

Yes, if you use CORS Anywhere as a server-side library, then you can use the setHeaders option to add request headers.

Documentation: https://github.com/Rob--W/cors-anywhere#server Example: https://github.com/Rob--W/cors-anywhere/blob/4814647a9d21f14858da282387a4295c17f2851d/test/test.js#L818-L847

Rob--W avatar Apr 19 '20 16:04 Rob--W

Amazing! Thank you very much for the prompt reply!

benzata avatar Apr 19 '20 17:04 benzata

Hi, can i also specify Headers that will only be sent if for example a domain rule is met?

unbekannt3 avatar May 06 '20 20:05 unbekannt3

Do you mean request headers or response headers?

In either case, CORS Anywhere does not have out-of-the-box support for domain-specific headers (request headers / response headers). If you want to change the (request/response) headers based on the requested URL only, then you could use a different http(s) server in front of CORS Anywhere (example) and directly modify request.headers (for request headers) or use response.setHeader (for response headers).

Rob--W avatar May 06 '20 20:05 Rob--W

Yes, if you use CORS Anywhere as a server-side library, then you can use the setHeaders option to add request headers.

Documentation: https://github.com/Rob--W/cors-anywhere#server Example: https://github.com/Rob--W/cors-anywhere/blob/4814647a9d21f14858da282387a4295c17f2851d/test/test.js#L818-L847

I tried to use setHeaders in the server for the "origin" and "referer' headers, but they seem not to change as they are both still https://localhost:port instead of the ones I defined. Is there a way to manipulate these two headers to specify a target of my choice, instead of showing the localhost server domain?

Thank you.

freQniK avatar Jan 11 '22 06:01 freQniK

I tried to use setHeaders in the server for the "origin" and "referer' headers, but they seem not to change as they are both still https://localhost:port instead of the ones I defined. Is there a way to manipulate these two headers to specify a target of my choice, instead of showing the localhost server domain?

The option should work. How are you setting the option, and how do you know that the headers aren't changing?

Rob--W avatar Jan 11 '22 10:01 Rob--W

I look at the headers in Firefox Developer->Network for a specific javascript to be downloaded for the page to work. I go to http://ip:8080/http://locaton.com and here is what I see in the Developer:

firefox

I set the option as follows:

 cors_proxy.createServer({
           ...
           ...
           ...
setHeaders:  {"referer": "https://desiredwebsite.com/stuff", "origin" : "https://desiredwebsite.com/stuff"},
           ...
           ...
           ...
}).listen(port, host, function() {
  console.log('Running CORS Anywhere on ' + host + ':' + port);
});


Any help is much apprecaited.

Thanks.

freQniK avatar Jan 12 '22 00:01 freQniK