Adding custom header in HTTP before redirect

14,112

I suppose you mean redirecting by window.location.

It's impossible to redirect to a page with custom headers set, no matter what language or framework you use. In other words, there's no way to trigger an HTTP redirect and cause the client to add a custom header.

The only way for a site to instruct a browser to issue an HTTP request with a custom header is to use the XMLHttpRequest object. And it needs CORS implemented on the target server to allow such ajax requests.

The closest workaround you can come up with would be to act as a proxy. e.g., Send ajax requests with custom HTTP headers set, retrieve the response and inject it into the DOM which is a case for building upon the wrong idea.

Share:
14,112
Jared Teng
Author by

Jared Teng

Mystery

Updated on June 28, 2022

Comments