How to use Rewrite Header tool in Charles Proxy

Introduction

During local development you might want to override headers for various reasons like bypassing CORS locally to work with production files etc.

“Rewrite Header” comes handy in such cases where you can overwrite HTTP Headers from request and responses without making any changes to your codebase.

Rewrite Header can also be used to

  • Simulate different UserAgents
  • Injecting or Modifying Authentication Tokens
  • Testing Localization and Language Preferences

Setting up Rewrite Header in Charles Proxy is little complex. You can follow the steps below to configure Rewrite Header with ease.

Browser Extension, that just needs you to fill 1 fields and doesn’t have VPN issues, is also explained later in this post. You can also use that in place of Charles Proxy.

Charles Proxy’s Rewrite Header Tool: How It Works

Configuring the Rewrite Header tool in Charles Proxy can be a time-consuming process. It requires navigating through a series of options, which can be difficult to find and set up, especially for users unfamiliar with the tool.

How to Configure Charles Proxy’s Rewrite Header Tool

  1. Open Charles Proxy and ensure that your proxy is enabled and traffic is being captured.

  2. Navigate to the Tools Menu:

    • In the top menu, click on Tools.
    • From the dropdown, select Rewrite.

charles proxy response status
  1. This will open the rewrite settings window Here check Enable rewrite box and click Add

Rewrite Settings popup
  1. Rename the rule to your liking and add a location to which the rule should be applied to
    • Protocol: Here you can select your site’s protocol http or https
    • Host: Here you can enter the host/domain that you want to apply the rule to.
    • Port: You can specify the port on which your site is running.
    • Path: Define the path if you want the rule to apply only to specific paths on the host.
    • Query: Here you can define the query parameters which should be targeted.
Charles location selection
  1. Now Save the location and click on add in the actions section
Rewrite header rule pop up
  • Type: The type tells Charles what to modify. Here we want to select Modify header.
  • Where: Decide whether to apply the change on the request, the response, or both. Since we want to allow CORS we will modify only the response.
  • Match: You need to tell Charles when to apply the rule. This is done by matching specific text in the request or response, such as a URL, a header, or a status code. Here we want to replace the value of Access-Control-Allow-Origin regardless of its current value so we will match the name and keep the value field empty to match all values.
  • New/Replace: Once a match is found, Charles either adds or replaces the text you’ve specified. For example, in this case we want to change the Access-Control-Allow-Origin header, Charles will replace it with the new value we provided.

Tips:

  • Rewrite rules can be tricky to get right. It’s best to test them in small steps and make sure they work as expected.
  • Regex makes matching flexible but more complex, so use it carefully if needed.
  1. After saving this you should be able to see the rule and its modifications
Rewrite settings pop up after rule setup
  1. Now visit the site you selected and you can see the header in developer tools
Modified header in Devtools

I hope you are able to configure Rewrite Header tool, if you are facing issues in setup of SSL read about SSL setup on Charles Proxy official documentation.

Due to this complicated setup process of Charles Proxy and issues with VPN we, at Requestly, came up with a smart solution. We developed a Browser Extension that can sit inside the browser and use browser’s APIs to intercept and modify your network requests and responses.

Modify Header rule in Requestly

Requestly is designed differently so it doesn’t need any SSL configuration and hence works seamlessly with your VPNs. Rewrite Header is simplified as “Modify Header Rule” in Requestly. With just 2 inputs i.e. source URL matching condition, Header value.

There are more advanced rules in Requestly & other features to help you test the working of the rule along with details of how to use this rule are explained below.

Requestly's Modify header config screen
Overview of Configuration Options
  1. Source Condition: This determines which requests will be redirected.
  2. Type of Header: Select the type of header you want to modify, you can add separate modifications to both
  3. Header Value: Enter the header you want to remove.
  4. Action: The type of modification you want to do to the header
  5. Add Modification: Include additional header modifications.

Steps to Configure Requestly’s Modify Header Rule

  • Install Requestly Extension: Download and install Requestly’s browser extension.
  • Open Requestly Dashboard: Visit app.requestly.io and log in.
  • Click on the Rules tab and then select New Rule.
  • Choose Modify Header as the rule type.
  • Enter the URL or URL pattern in the Source Condition field.
  • Specify the headers you want to add, modify, or remove .
  • Name your rule and click Save.
After saving the rule, you can test it on your desired API. For convenience, we’ve also created a shared rule for Modify Header, which you can import by clicking the button below.

Or create your own Rule by following the setups below

Interactive guide

Check out this interactive and easy explanation of how to create this rule :

Other Use Cases

Modify Header rule in requestly is a powerful tool and can serve many purpose, it can also be used for other usercase like :

  1. Add Custom Authentication Tokens: You can automatically add authentication tokens to requests by modifying headers like Authorization. This is helpful for testing APIs or accessing resources that require token-based authentication.
  2. Controlling Cache Behavior Add or modify cache-control headers such as cache-control to ensure you’re testing the most up-to-date versions of your assets.
  3. Simulate Different Languages: Adjust the Accept-Language header to test how your website appears in different languages, ensuring that localization and internationalization are functioning correctly

Migrate from Charles proxy

If you already have a Charles Proxy setup and want to give Requestly a try, You can import these tool settings in Requestly in just few clicks Requestly currently supports following tools that you can import from Charles Proxy:
  • Rewrite
  • Map Local
  • Map Remote
  • No Caching
  • Block lists
  • Block Cookies

Steps to import

  1. In Charles Proxy, go to the top menu bar and select Tools > Import/Export Settings.
Charles proxy menu Import Export settings
  1. In the popup window that appears, switch to the Export tab. Under the Tools section, select the tools you want to export and click the Export button at the bottom right.

Import Export Setting popup
    1. You can also open it from https://app.requestly.io/import-settings-from-charles

      Open the Requestly dashboard. If you don’t have any existing rules, you’ll see an Import settings from Charles Proxy .

Import from Charles proxy in requeslty dashboard
  1. Upload or drag your exported Charles .xml file into Requestly.

Import charles proxy settings poip up
  1. Once the import is successful, your Charles Proxy settings will be converted into Requestly rules.

Conclusion

I hope you have got a clear understanding of both the Rewrite Header tool in Charles Proxy and how Requestly can achieve the same results with greater ease. While Charles Proxy effectively handles the task, Requestly offers a modern, simple and efficient experience.

Since Requestly operates directly from your browser and leverages built-in browser APIs, there’s no need for complex SSL configurations, eliminating the VPN issues often encountered with Charles Proxy. Plus, you don’t need to switch between different tools — everything you need is right in your browser.

Love for Requestly is reflected in its 4.4 ⭐ rating from over 1,200 users on the Chrome Web Store. Requestly is being used by 200K+ developers across the world.

Happy Debugging!!!

Explore More

Share this article:

Subscribe to our weekly newsletter !

Join 10k developers and QAs to get weekly updates with Requestly's newsletter.​

This article was written by:

Picture of Dinesh Thakur

Dinesh Thakur

Dinesh Thakur, fascinated by technology since childhood, has mastered programming through dedication. Whether working solo or in a team, he thrives on challenges, crafting innovative solutions.

Join 10k developers and get weekly updates with Requestly's newsletter.

Contents

Related posts