Simulating slow POST requests with Fiddler

Sometimes, your dev machine is too damned fast, and you need to slow down how something works in order to investigateĀ a potential bug. This post shows how to do that with a custom rule for Fiddler.

We recently had to make sure that a button on a web page worked like this: the user clicks the button; the button is disabled; the work completes; the button is re-enabled.

However, on a fast developer machine, the whole process can be far too quick. What you need to do is simulate the server taking a long time, so that you can visually confirm the delay.

Turns out you can use Fiddler to do that. It uses a strange JavaScript variant to do it. (Telerik; I’m pretty sure we wouldn’t mind it being plain old JavaScript, if that’s ok!)

Here’s what you need to do;

Start Fiddler.

In the “Rules” menu, choose “Customise Rules…”

About line 65, paste this fragment;

public static RulesOption("Delay &POSTs by 2s", "Per&formance")
var m_DelayPostResponses: boolean = false;

There will be similar pairs of lines thereabouts; just put it with the similar code.

What this does is register a menu option at Rules > Performance > Delay POSTs by 2s. It’ll appear when you save the file.

Then, at the top of the OnBeforeRequest(Session) method around line 162, paste this;

if (m_DelayPostResponses && oSession.HTTPMethodIs("POST")) {
  // active wait loop
  var msecs = 2000;
  var start = new Date().getTime();
  while(new Date().getTime() - start < msecs) { 
  }
}

This introduces a 2-second wait loop for POSTs, if you’ve turned the option on in the Rules > Performance menu.

So once you save this file, fiddler automatically reloads it and the toggling menu item appears. Use this whenever you want to test that your code works around slow POST methods.

Advertisements