Can Fiddler reply with content hosted on another server?

2 Answers 293 Views
Fiddler Classic
Alex
Top achievements
Rank 1
Iron
Iron
Alex asked on 18 Jan 2023, 08:31 PM
I am using the following code to serve a local HTML file when the URL of a web request contains a certain keyword.

if (oSession.uriContains("keyword")) {
  oSession["x-replywithfile"] = "D:/content.html";
}

Instead of a local file, is it possible for Fiddler to reply with a web page hosted on a remote server? Something like this...

if (oSession.uriContains("keyword")) {
  oSession["x-replywithfile"] = "https://www.domain.com/content.html";
}

Thank you!

Alex

2 Answers, 1 is accepted

Sort by
0
Accepted
Nick Iliev
Telerik team
answered on 20 Jan 2023, 06:30 AM

Hi Alex,

 

The x-replywithfile autoresponder flag utilizes the local file system and can't be used to access online resources available through the HTTP protocol. You would need to explicitly access this resource through an HTTP request, decode its body, and then use it to modify your own response body.

 

Regards,
Nick Iliev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Alex
Top achievements
Rank 1
Iron
Iron
answered on 20 Jan 2023, 11:54 AM
> You would need to explicitly access this resource through an HTTP request

All right, is there a FiddlerScript instruction for this?

I searched the web for a few minutes, and all I found was this, but the article was not referring to how to compose a HTTP(S) request from a script.

Thank you!

Alex
Nick Iliev
Telerik team
commented on 20 Jan 2023, 12:24 PM | edited

 

You can modify a request or response as shown in this documentation article. You can redirect all requests from one server to another as shown:

// Point all requests for one server to the same port on a different server
if (oSession.HostnameIs("www.example.com")) {
    oSession.hostname="test.example.com";
}

// Point all requests for one port to a different port on a different server
if (oSession.host=="www.example.com:8080") {
      oSession.host="test.example.com:9090";
}

// Point all requests for one server to a different server, including HTTPS tunnels
// Redirect traffic, including HTTPS tunnels
if (oSession.HTTPMethodIs("CONNECT") && (oSession.PathAndQuery == "www.example.com:443")) { 
        oSession.PathAndQuery = "beta.example.com:443"; 
 }
if (oSession.HostnameIs("www.example.com")) oSession.hostname = "beta.example.com"; 


If the modification happens after the request is executed, then you should modify the response body with utilSetResponseBody.

oSession.utilSetResponseBody(oBody);

 

If you need to obtain data from another endpoint, you can use the sendRequestAndWait method to issue the new request.

var oSD = new System.Collections.Specialized.StringDictionary();
var newSession = FiddlerApplication.oProxy.SendRequestAndWait(oSession.oRequest.headers, oSession.requestBodyBytes, oSD, null);

if (newSession.responseCode == 200)
{
    // custom code here
}

 

As a side note, in the context of our conversation about the Rules tab compared to FiddlerScript. This is one case where the above can be achieved easily using the Rules tab (in Fiddler Everywhere) or the AutoResponder (in Fiddler Classic).

An example of a similar rule in Fiddler Everywhere:

Alex
Top achievements
Rank 1
Iron
Iron
commented on 20 Jan 2023, 01:06 PM

I believe the 'sendRequestAndWait' instruction is what I need.

Thank you!

Tags
Fiddler Classic
Asked by
Alex
Top achievements
Rank 1
Iron
Iron
Answers by
Nick Iliev
Telerik team
Alex
Top achievements
Rank 1
Iron
Iron
Share this question
or