Skip to content Skip to sidebar Skip to footer

Adding Custom Header In HTTP Before Redirect

Is there any way to add a custom HTTP header in a HTTP redirect triggered by javascript? I'm looking for something that would add a customer header element to any redirect. Ther

Solution 1:

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.


Post a Comment for "Adding Custom Header In HTTP Before Redirect"