telerikfiddlercontent-length

In Progress Telerik Fiddler Web Debugger is there a way to adjust Content-Length automatically in AutoResponder?


I am using fiddler autoresponder to return a different JS file than the one loaded from my server originally. The adjusted file uses:

HTTP/1.1 200 OK
Cache-Control: private, max-age=31536000
Content-Type: application/javascript
...other headers
Content-Length: 37010

...the javascript code

At the top of the file, this Content-Length header is not automatically adjusted to the edited file though. So I have to try and load my changes, my app will crash because the Content-Length is wrong, but then I check fiddlers 'transformer' tab to see how many bytes my request body actually is, update that in my modified file, refresh again and then it works.

I have tried to change the encoding to chunked, so that I could leave out the Content-Length header, but I don't think my app knows how to decode chunked for some reason.

So my question is, is there any way to automatically update the Content-Length in the auto-responder?


Solution

  • You can simply use FiddlerScript in Fiddler classic to build your auto responder. That way the content-length is set automatically:

    static function OnBeforeRequest(oSession: Session) {
         // ... some other FiddlerScript code
    
         // host is e.g. "localhost:3000"
         if (oSession.HostnameIs("<host>") && oSession.uriContains("<file name>.js")) {
            oSession.utilCreateResponseAndBypassServer();
            oSession["ui-backcolor"] = "lime"; // Makes it more visible
            if (!oSession.LoadResponseFromFile("<file path>.js")) {
                throw new ApplicationException("LoadResponseFromFile Failed!! ");
            }
            // Just loads forever if Content-Length is not added
            oSession.oResponse["Content-Length"] = oSession.responseBodyBytes.GetLength(0);
        }
    }