Click here to Skip to main content
15,860,943 members
Articles / Programming Languages / C#

Fiddler Extension - HTTP Response Code Analyzer

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
15 Jul 2010CPOL5 min read 37.7K   2.8K   31  
Fiddler extension to analyze HTTP response codes

Introduction

This article illustrates building a Fiddler extension using C# to analyze / summarize HTTP response codes. My goal is to demonstrate how to build extensions that interacts with Fiddler UI.

Background

Fiddler is a web-debugging proxy that automatically attaches itself to the WININET chain, so it could capture all requests and responses that goes through the chain. It is able to analyze, tamper all requests and responses it captures. Fiddler's capabilities could be extended by building custom rules, extensions and inspectors using JScript.NET and/or C#.NET (current accepted version is 2.0). This article discusses about building interactive extension with rich UI.

Using the Code

I have attached compiled extension (DLLs.zip containing FiddlerRespCodeAnalyzer.dll and SessionStatusControl.dll), so you will be able to copy these .dlls to "My Documents\Fiddler2\Scripts" folder and check its functionality. Also, I have attached the relevant code in zip files (FiddlerRespCodeAnalyzer.zip and SessionStatusControl.zip).

Shown below is a screenshot of the extension:

ResponseCodeAnalyzer screenshot - Click to enlarge image

Let's look at the functionality of this extension first. Response Code Analyzer uses sessions captured by Fiddler and will summarize the composition of different response code types (100s, 200s, 300s, 400s & 500s) in a pie chart. Responses with client errors (400s) and server errors (500s) are being populated into a separate grid with their respective color coding and a description of their response code. Additionally, the user will be able to highlight responses that belong to a particular response category with a respective color. For an example, user can highlight / select all client error responses (400s) in Fiddler main window by clicking on client error label. This extension has two main parts, user control ("SessionStatusControl") and logic that populates the user control ("FiddlerRespCodeAnalyzer").

First, you need to have Fiddler 2.2.4.6 or a higher version installed in your computer and .NET CLR 2.0 to develop this extension. Fiddler is freely available via www.fiddler2.com.

Now we will look into the user control. The user control supports the following functionalities:

  • Displaying the pie chart
  • Displaying number of different types of response codes from selected responses
  • Displaying the details of error responses in a grid
  • Ability to highlight responses in Fiddler main window by clicking on relevant response type summary labels
  • Ability to select responses in Fiddler main window by clicking on relevant response type summary labels

I have compiled this user control as a separate DLL as against creating it in the same project that contains logic for populating the UI. The user control contains the following major components:

  • SplitContainer; panel-1 hosting response code summary and details, panel-2 hosting the pie chart
  • 8 Lables; to display the summary of response codes
  • DataGridView; to display details of error responses
  • PictureBox; to display the pie chart

I was able to access and change attributes of session display list view component of Fiddler UI. This was possible using the code segment shown below, as done in selectAllSessions method. You can download "SessionStatusControl", unzip it and analyze the code for more details:

C#
ListView.ListViewItemCollection lvItems = FiddlerApplication.UI.lvSessions.Items;

Now let's look at the program that has the logic to populate user control / UI. You have to follow these steps to create an extension to Fiddler, also described in www.fiddler2.com.

  • Projects should target ‘Any CPU’ to ensure compatibility with 64bit Fiddler.
  • Create a new Project of type Visual C# Class Library.
  • Set the Fiddler.RequiredVersion attribute [assembly: Fiddler.RequiredVersion("2.2.4.6")]
  • Implement Fiddler interface(s) that is relevant to your task (IFiddlerExtension, IAutoTamper, IHandleExecAction)
  • Drop your assembly .DLLs (FiddlerRespCodeAnalyzer.dll and SessionStatusControl.dll) in your \My Documents\Fiddler2\Scripts folder (or use \Program Files\Fiddler2\Scripts to make it available to all users on the machine)
  • Start Fiddler.

In this extension, I have implemented the IFiddlerExtension interface and implemented its methods OnLoad and OnBeforeUnload. In the constructor of class RespCodeAnalyzerExt I have instantiated my user control and its components. Then, I have added my user control instance to Fiddler UI in OnLoad method as indicated below. It is important to note that Fiddler UI will be available only from this point onwards.

C#
FiddlerApplication.UI.tabsViews.TabPages.Add(oPage); 

In order for me to analyze the session status codes of sessions that the user has selected, I need to capture those session details form session display list view of Fiddler UI. I'm achieving this in OnLoad method by registering an event handler to CalculateReport event through CalculateReportHandler delegate as indicated below:

C#
FiddlerApplication.CalculateReport += 
	new CalculateReportHandler(FiddlerApplication_CalculateReport);

FiddlerApplication_CalculateReport has the logic of analyzing session status codes of selected sessions. It categorizes available session status codes to different categories (100, 200, 300, 400 & 500) and remembers them, displaying these summary details as a pie chart. This method also performs special processing required for response codes 400s and 500s by displaying the relevant details with a full description of relevant codes as indicated below:

C#
if (code == 4 || code == 5) <
{ 
//Display error session details 
String[] row = { httpResponse.ToString(), 
    ((HTTP_ERROR_ResponseCode)httpResponse).ToString(), "HTTP", s.hostname, s.fullUrl };
gridSessionDetails.Rows.Add(row);
}

I'm maintaining the error codes (400s & 500s) in an enum structure as shown below:

C#
//This ENUM represents HTTP response codes 400s and 500s
enum HTTP_ERROR_ResponseCode
{
//400s
Bad_Request = 400,
Unauthorized = 401,
.

You can download "FiddlerRespCodeAnalyzer", unzip it and analyze the code for more details.

Points of Interest

There aren't many articles explaining how to build extensions that interact with Fiddler UI. In this article, I tried to fill that gap. So, by referring to this code, someone with a great imagination could build a very useful extension.

History

  • 22/06/2010 - This is the initial version of the Fiddler extension, Response Code Analyzer
    • FiddlerRespCodeAnalyzer - 1.0.0.0
    • SessionStatusControl - 1.0.0.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Sri Lanka Sri Lanka
Software engineer with 5+ years of IT industry experience in .NET, Java, PEGA, Jacada (MainFrame env), PERL & C++.
Business domains - Banking, Insurance, ERP

Bachelor's @ UCSC
Masters @ SLIIT

Research Interests
*Bio-Informatics
Method for predicting membrane spanning regions of trans-membrane proteins using HMM & HTK
*Computer Immune systems

Blog
http://www.bioinformaticssrilanka.blogspot.com/

Comments and Discussions

 
-- There are no messages in this forum --