This is a migrated thread and some comments may be shown as answers.

AutoRespond without using AutoResponder rather programmatically

1 Answer 172 Views
Extensions and Customization
This is a migrated thread and some comments may be shown as answers.
Rohit
Top achievements
Rank 1
Rohit asked on 10 Aug 2019, 11:46 AM

Hi,

I've similar need as mentioned in another post: https://www.telerik.com/forums/automatic-saving-of-responses-into-autoresponder, but don't want to pile up the AutoResponder. The AutoResponder UI is a simple list view and when I pull SAZ sessions, I'm finding it difficult with other existing rules. I wonder if something can be done programmatically to locate the session in a SAZ file and serve the response accordingly bypassing the UI. I'm using below code snippet to locate a session in the SAZ, but not finding a way to serve the response body stored in SAZ file.

for (var i1:int = 0; i1<sSessions.Length; ++i1)
{
    FiddlerObject.log("sSessions: " + i1 + ": " + sSessions[i1].url);
 
    if(sSessions[i1].url === 'example.com/default.css') {
        //FiddlerObject.log("sSessions: " + i1 + ": " + sSessions[i1].GetResponseBodyAsString());
        //TODO logic to map oSession.response = response stored in SAZ file
    }
}

 

Can anyone help? The above sample code snippet may not be the best one, and appreciate for improved version.

Cheers,

1 Answer, 1 is accepted

Sort by
0
Rohit
Top achievements
Rank 1
answered on 14 Aug 2019, 07:02 AM

From the question posted on StackOverflow at: https://stackoverflow.com/questions/56962825/process-saz-files-using-fiddlerscript-or-extension

After exchanging few notes with Eric and researching a bit, I got this working with below snippet to certain extent:

var sSessions = Utilities.ReadSessionArchive(@"C:\Fiddler\WIP.saz", true);
 
for (var i1 = 0; i1 < sSessions.Length; ++i1)
{
  if (oSession.fullUrl == sSessions[i1].fullUrl)
  {
      if (oSession.state < SessionStates.SendingRequest)
      {
          oSession.utilCreateResponseAndBypassServer();
      }
 
      oSession.oResponse.headers = sSessions[i1].oResponse.headers;
      oSession.responseBodyBytes = sSessions[i1].responseBodyBytes;
      return;
  }
}

 

However, I ran into 2 new issues:

1) For HTTPS connections, the CONNECT method / tunnel is taking too long, so at browser / client side, the requests aren't getting completed or getting timed out. How to get rid of this CONNECT entirely when reading from SAZ or how to get the actual URL for which the CONNECT url is invoked?

2) The Utilities.ReadSessionArchive is reading the entire SAZ and all sessions are getting listed in Fiddler UI though the code is looking only for a particular session (using if condition). How to read the SAZ without listing the sessions in Fiddler UI?

For the CONNECT / Tunnel to connections, I could fake it, but it work for sessions not present in the SAZ file. It needs to establish active network connection to get the live content. I don't see any code to get the actual browser originated URL, which follows a CONNECT method. Hoping Eric can help me here.

if (oSession.isTunnel) //or, oSession.HTTPMethodIs("CONNECT")
{
    oSession["X-ReplyWithTunnel"] = "Work offline; generate a fake tunnel...";
}

 

Tags
Extensions and Customization
Asked by
Rohit
Top achievements
Rank 1
Answers by
Rohit
Top achievements
Rank 1
Share this question
or