Fiddler to request HTTP requests with timing respected

1.4k Views Asked by At

Can HTTP request be replayed using Fiddler with caputered session timing respected?

I tried to replay a session with fiddler but the replay sends requests to the maximum speed ignoring the time of capture.

I tried to add this to onBeforeRequest() function:

if (oSession.HostnameIs("example.com") && oSession.uriContains("page.html")) {
    // I tried this
    System.Threading.Thread.Sleep(1000);
    // and this
    // oSession["response-trickle-delay"] = "30"; 
}

but doesn't work very well and I must to repeat this for every captured URI.

I need to replay a captured session but the requests must be sent with the same delay as recorded. Is it possible?

2

There are 2 best solutions below

0
On BEST ANSWER

Fiddler does not itself attempt to respect relative timings when replaying requests.

You could write script or an extension that would do so, based on each Session object's oTimers data.

1
On

here is my solution, it maybe useful to others:

static function DoTimedReplay() {
    var oSessions = FiddlerApplication.UI.GetSelectedSessions();
    if (oSessions.Length == 0) {
        oSessions = FiddlerApplication.UI.GetAllSessions();
        if (oSessions.Length == 0) {
            FiddlerObject.alert("No session available.");
            return;
        }
    }

    FiddlerObject.StatusText = "Start replay";
    var iStart = Environment.TickCount;
    for (var x:int = 0; x < oSessions.Length; x++) {
        var iDelay:Int32 = x == 0 ? 0 :
            System.Math.Round(
                (oSessions[x].Timers.ClientBeginRequest - oSessions[x - 1].Timers.ClientBeginRequest).TotalMilliseconds
            );
        replay(oSessions[x], iStart + iDelay);
    }
    FiddlerObject.StatusText = "Replay Done";
}

static function replay(oSession: Session, iDelay: Int32) {
        if (!String.IsNullOrEmpty(oSession["X-Replayed"]))
            return;
        try {
            var oSD = new System.Collections.Specialized.StringDictionary();
            oSD.Add("X-Replayed", "True");
            while (iDelay > Environment.TickCount) {
                Application.DoEvents();
            }
            FiddlerApplication.oProxy.SendRequest(oSession.oRequest.headers, oSession.requestBodyBytes, oSD);
        } catch(ex) {
            var iTickCount = Environment.TickCount + 10000;
            while (iTickCount > Environment.TickCount) {
                Application.DoEvents();
            }
        }
}

Cheers