Fiddler: Redirecting Traffic

A while back I ran into an interesting problem. As any good developer knows, you don’t make code changes in prod. You typically have a series of different environments set up. Where I work, we have 5 environments that we work through.

Development -> Pre-Test -> Test -> Beta -> Production

With this process, we start off having the code only available on the developer’s machine, then we check the code in and QA will do a quick test on the feature/defect. We then move our code to an internal test environment. Once we decide we want a release candidate, we move to Beta. Finally when we’re ready, we release to production.

The only serious problem that we seem to keep running into is having a mobile app that is pointed to the wrong environment. Now of course, there are a lot of ways to solve this problem, but sometimes you’re in a rush to get things done and you don’t have time to set everything up correctly. So here’s what I came up with instead.

Fiddler Rules


If you’re not familiar with Fiddler rules, you should be. There’s a lot of cool things you can do with them. Notably, you can throttle network connections, or you can flag slow network calls.

We’ve done both of these at work a few times. When working on performance, we can just use our web app and look in fiddler to figure out where our slow network calls are. This makes things a lot better than someone just saying “I think this could be sped up, probably.” And when trying to decide if something is slow or fast, we can have people throttle their network connections. This way we can see how our application works when outside of our super fast company network.

As far as I’ve been able to tell, Fiddler’s rules are written in JavaScript. If you don’t know JavaScript, you should spend a weekend to learn it. Fiddler’s JavaScript is super basic so you don’t need anything other than the basics to get by.

There used to be no good way to know how to do Fiddler’s scripting stuff without trial and error, or an obscure hard to find api documentation. Luckily, nowadays there’s a supported tool for you. Just install the Fiddler2 ScriptEditor (direct link, about page)

Once you’ve got that installed, just open Fiddler and click  Rules -> Customize Rules...

Redirecting Traffic


Now here’s where the big part is. We ran into a case where we needed to point a test iOS build to a beta web server. So what we did was point the iOS device to a Fiddler proxy (instructions on how to do that are here). Once that’s done you just need to set up a rule like this

You don’t need to get rid of any of the other things inside of OnBeforeRequest, just add something where you change the host, and you’ve got a redirect.

You may run into issues if there are html rewrite rules that rewrite the url, but like always it always depends on what exactly your situation is.

 

Leave a Reply

Your email address will not be published. Required fields are marked *