Modify Headers

Modify HTTP request and response headers with Requestly. Learn how to add, remove, or override headers for debugging, testing, and customizing API requests.


HTTP(s) Headers are key-value pairs that pass additional information with HTTP(s) requests or responses. This document explains how developers can use Requestly to modify these headers by adding, removing, or overriding values easily.

Why Use the Modify Headers Rule

  • Open Websites in an iframe for Testing: Headers like X-Frame-Options and Content-Security-Policy prevent pages from being opened in iframes to avoid clickjacking. Use Requestly to modify these headers for testing purposes.

  • Remove Content-Security-Policy: The Content-Security-Policy header restricts the injection of external scripts. Requestly can remove this header for testing purposes.

  • Debugging CORS Issues: To resolve CORS errors in browsers, modify response headers such as Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, and Access-Control-Allow-Credentials.

  • Access the Kubernetes Dashboard: Modify the Authorization header to include Authorization: Bearer <token> for accessing the Kubernetes dashboard. [Find more information here.]

  • Modify Headers in Safari: Use the Requestly desktop app to modify headers in Safari and other applications.

Steps to Create Header Rules

1

Add a New Rule

Navigate to the HTTP Rules section and select Add Rule. Choose Modify Headers and click the Request Headers tab.

2

Name and Describe Your Rule

Provide a descriptive name for the rule to keep your setup organised. Optionally, add a brief description explaining its purpose for easier identification later.

3

Define Conditions

Add conditions using Source Condition and Source Filters to target specific requests. Conditions can include URL, Host, or Path with matching options such as Regex, Contains, Wildcard, or Equals.

Example: Let’s use an echo endpoint that returns request headers, body, query params etc as JSON response.

For the next step, choose the option you want to modify. You can modify both the request and the response within a single rule.

Step 4: Specify Header Modifications

In the Header Modification section, specify key-value pairs to add, remove, or override headers. If you want to modify request headers, add values under the Request headers tab.

Step 5: Save and Test the Rule

Save the rule and try opening the URL in the new tab to see the changed values of header.

Due to technical limitations, modified request headers won’t appear in the browser network panel. However, the modified headers are sent to the server and can be verified in the Desktop App Network Traffic Section.

Updated on