class RetryRequest
{
private var oWaitForIt = new System.Threading.ManualResetEvent(false);
function Retry(oSession: Session, iRetry: int)
{
var oSD = new System.Collections.Specialized.StringDictionary();
oSD["X-RetryNumber"] = iRetry;
oSD["ui-Comments"] = ("Retry #"+iRetry+". Replaying Session #"+oSession.id);
oSD["ui-Color"] = "green";
var newSession = FiddlerApplication.oProxy.SendRequest(oSession.oRequest.headers, oSession.requestBodyBytes, oSD);
newSession.add_OnStateChanged(fnCallback);
oWaitForIt.WaitOne();
return newSession;
}
function fnCallback(sender:Object, ea:Fiddler.StateChangeEventArgs)
{
if (ea.newState >= SessionStates.Done) oWaitForIt.Set();
}
}
static function OnReturningError(oSession: Session) {
if ((oSession.responseCode == 502) || (oSession.responseCode == 504)) return;
if (!String.IsNullOrEmpty(oSession["X-RetryNumber"]))
return;
for(var iRetry: int = 1; iRetry < 5; ++iRetry)
{
var oSD = new System.Collections.Specialized.StringDictionary();
oSD.Add("X-RetryNumber", iRetry.ToString());
var newSession = FiddlerApplication.oProxy.SendRequestAndWait(oSession.oRequest.headers, oSession.requestBodyBytes, oSD, null);
if (200 == newSession.responseCode)
{
// If we were successful on a retry, bail here!
oSession.oResponse.headers = newSession.oResponse.headers;
oSession.responseBodyBytes = newSession.responseBodyBytes;