rgareth
rgareth

Reputation: 3536

Chrome extension background XMLHttpRequest proxy server

I have a background task in a Chrome Extension that performs some polling/checking. In error cases, I want to retry the check using a different CDN server to verify if it's a site-wide problem or just a CDN node affected. The challenge is how to control to which CDN node to send to.

e.g. let's say I'm checking www.company.com and typically that will be served by server21.cdn.co

Now if that fails I want to check server5.cdn.co and server10.cdn2.co for the same content to see if there's a correlation.

These checks are done using XMLHttpRequest but I can't find a way to specify which host/proxy to use per-request.

I wouldn't want to "hijack" the entire browser's proxy server settings because it would cause all other pages/tabs to fail.

Upvotes: 0

Views: 413

Answers (2)

rgareth
rgareth

Reputation: 3536

To clarify, this can't be done because XMLHTTPRequest forbids overriding the Host header in requests. See https://security.stackexchange.com/questions/46702/how-can-i-control-the-content-of-the-http-host-header-in-requests-issued-from-my/ for an explanation of why.

Conceptually/technically it's easy to do if it weren't for this security issue. For example with curl: curl --verbose --header 'Host: www.example.com' 'http://10.1.1.36/the_url_to_test'

But as mentioned in the question, we're stuck inside a Chrome extension so curl is not an option!

Upvotes: 1

Xan
Xan

Reputation: 77523

If it's load-balancing performed on the DNS level (which is most probable), you can't affect which server you actually contact at all.

Upvotes: 1

Related Questions