Fiddler – Great tool for web developers – Custom Rules feature

14 Jul
2011

Fiddler is a web debugging proxy which logs all HTTP(S) traffic between your computer and the Internet.
It’s really great tool for developers when developing a web application or http consumer application. It helps us to inspect all HTTP(S) traffic, set breakpoints, create auto-responders for specific requests to stub out some data.

But as default Fiddler logs all HTTP(S) traffic and log list can be very long if you are using/running other applications that creates HTTP(S) traffic. Fiddler provides a scriptable rules mechanism. It uses javascript syntax and provides a object model to create custom rules.

You can filter out requests from Fiddler log screen by using customized rules. For example if you want to see requests to a specific list of domains (internal development servers?) you can just use below script.

To add rules, choose Customize Rules on Fiddler’s Rules menu. Enter code inside the suggested function and save the file. Fiddler will automatically reload the rules.

in OnBeforeRequest method :

if (oSession.uriContains("mydevelopmentserver1.int")){
oSession["ui-hide"] = "true"; // any string value is OK to hide
}

Fiddler custom rules object model provides more functionality. For example to return a 404 response for a specific request from Fiddler level (actually request doesn’t hit the real endpoint).

in OnBeforeRequest method :

if (oSession.uriContains("mydevelopmentserver1.int/productservice")){
oSession["ui-color"]="orange";
oSession["ui-bold"]="true";
oSession.oRequest.FailSession(404, "Blocked", "Fiddler blocked product service request");
}

Fiddler is a really powerful tool and I strongly suggest to keep it running when you are developing a web application for HTTP(S) client application.

For more information about Fiddler scripting samples you can check this web page.



Comment Form

top