HTTP Headers
X Forwarded Host
The HTTP X-Forwarded-Host
request header is an informal standard used to identify the original host requested by the client in the Host
HTTP request header.
When dealing with reverse proxies such as load balancers or Content Delivery Networks (CDNs), the host names and ports may differ from the origin server that processes the request. In such cases, the X-Forwarded-Host
header helps determine the original host that was used by the client.
A more formalized version of this header is the HTTP Forwarded
header, although it sees less frequent usage.
Syntax
X-Forwarded-Host: <host>
Directives
Example
X-Forwarded-Host: id42.example-cdn.com
How to Modify Header using Requestly
Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the X-Forwarded-Host header. This can help you simulate requests coming from different hosts during development or testing without changing your server setup. Steps to Modify the X-Forwarded-Host Header:
- Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
- Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
- Add a new header modification:
- Under “Action”, select “Add” or “Override”.
- In the “Header Name” field, enter X-Forwarded-Host.
- In the “Header Value” field, enter the host value you want to use (e.g., example.com).
- Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
- Save the rule.
Once set up, Requestly will inject the X-Forwarded-Host header into all matching requests, allowing you to test how your application behaves when requests come from different hosts. Modifying the X-Forwarded-Host header is useful when you want to test proxy or routing behavior in your application or ensure your server handles forwarded host information correctly without changing real DNS settings.
Table of Contents
- No headings found.