Tuesday, December 10, 2013

Custom Rules in Fiddler

I needed to setup a filter in Fiddler so that I could view only JSON requests being made from my application. The default filter doesn’t allow for viewing only JSON requests. But luckily Fidller allows you to setup custom rules. Here is what I did:

Within the class “Handlers” add the following lines of code:

public static RulesOption("Display Only &Json Requests")
var m_bShowOnlyJsonRequests: boolean = false;

The above lines will add a Menu option under rules, that will easily allow you to turn on or off the JSON filtering.

image

Next, within the method: static function OnBeforeRequest(oSession: Session), add the following lines of code:

if (m_bShowOnlyJsonRequests && oSession.oRequest["Content-Type"] != "application/json"){
                oSession["ui-hide"] = "true";
          }

The above lines of code allow filters to display only those sessions that have a content-type header set to “application/json”.

As simple as that!

Notes:

1. The biggest problem that I have found is that there is hardly any documentation regarding the methods and properties available within the script file or off the oSession object (which is of type Session).

2. I think the script is based of JScript. I just wrote my code to resemble C# and it worked for my simple filter.

3. Samples from FiddlerBook site: http://fiddlerbook.com/Fiddler/dev/ScriptSamples.asp

4. Fiddler Script Editor is a pretty good tool that can help writing complex rules (it provides some documentation, though it wasn’t always helpful). http://fiddler2.com/fiddlerscript-editor

5. More Samples: http://fiddler2.com/documentation/KnowledgeBase/FiddlerScript/ModifyRequestOrResponse

6. Session object properties/flags: http://fiddler2.com/documentation/KnowledgeBase/SessionFlags

No comments: