I have a reverse proxy server, which redirects you to different services depending on the Host header.
However when making requests to this server using a browser, the Host
is always set to the domain name in the URL. I tried:
fetch("http://foo.com", {"headers":{"Host":"bar.foo.com"}})
But it doesn't work
The Headers interface of the Fetch API allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing headers from the list of the request's headers.
The Host request header specifies the host and port number of the server to which the request is being sent. If no port is included, the default port for the service requested is implied (e.g., 443 for an HTTPS URL, and 80 for an HTTP URL). A Host header field must be sent in all HTTP/1.1 request messages.
Host
is one of the forbidden header names:
A forbidden header name is an HTTP header name that cannot be modified programmatically.
It won't work. You cannot set the forbidden Headers on making the requests through browsers.
You can get the list of forbidden headers here - https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name
Similar answers here:
Ajax request: Refused to set unsafe header
Not able to set HTTP Host header on $.ajax request
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With