Add an HTTP Request Header Using Fiddler CustomRules Magic

In one of my projects, we utilize a custom HTTP header to determine certain properties of the request/user making the request. Now under normal production scenario, the Network Load Balancer (NLB) adds the HTTP header but I had to simulate the behavior without, obviously, having access to an NLB.

As it turns out, Fiddler comes to your rescue! (God Bless Eric Lawrence for this gift to developer-kind). Fiddler has the option to intercept requests matching a pattern (hostname, URL, and the like) and then you can do pretty much anything you like with the request. THIS LINK has a cheat-sheet for the scripts

Let’s see how to add an HTTP header:

Fire up Fiddler (I have version 4.4.9.3, but this option has been available since a long time)

Open up the Rules menu and select customize rules

This will prompt you to download syntax helper (this is optional) – download the tool if you can – I’m behind a corporate firewall so this is not an option for me. Fear not, the syntax of the CustomRules.js is pretty straight-forward and our friend Fiddler keeps a backup copy. If you ever make a mistake, just delete you CustomRules.js and Fiddler will regenerate one for you.