Autorespond with script

5 posts, 0 answers
  1. Dominic
    Dominic avatar
    3 posts
    Member since:
    Sep 2015

    Posted 07 Sep 2015 Link to this post

    Hi there,

    can you help me? I want to search and replace ainside a html-file.

    It means there is a request like "index.html" and than I want to replace a part of this with a local snippet and at the end it should be delivered to the brower as "the respond"

     

    At the Moment I write a Funktion and call it

    *script:TestFunc

    It is called because I see a log, but I do'n't know what's next :-/

    Thanks!

     

    Cya

    Dominic

  2. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 08 Sep 2015 Link to this post

    The AutoResponder's *script rules are run on requests, not responses. The AutoResponder is used to respond to requests itself, not to manipulate responses from the network. If you had an already complete response (or could create one entirely from script without hitting the network) you'd use a *script rule.

    From the sound of it though, you want your request to be sent to the network and you just want to modify the response that comes back. If so, what you need to use is script inside your OnBeforeResponse ​method. See e.g. http://docs.telerik.com/fiddler/KnowledgeBase/FiddlerScript/ModifyRequestOrResponse 

    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Dominic
    Dominic avatar
    3 posts
    Member since:
    Sep 2015

    Posted 09 Sep 2015 Link to this post

    Thanks for your answer.

    To use the OnBeforeResponse ​method it's not a good way for me, I know this method. I had to switch this rules on/off in a simple way.

    What to you think about this:
    1. the requests...
    2. I load the original site with js
    3. I modify the original site
    4. I return the motified site as the response

     

     Do you have a small example how I can give a response with a script?

    Thanks!

     

    Cya
    Dominic

  4. Dominic
    Dominic avatar
    3 posts
    Member since:
    Sep 2015

    Posted 09 Sep 2015 Link to this post

    I mean an example ​with a static response at a script :-)
  5. Eric Lawrence
    Admin
    Eric Lawrence avatar
    833 posts

    Posted 09 Sep 2015 Link to this post

    If the goal is simply to have an easy way to turn on and off the behavior inside OnBeforeResponse, that's easy-- look at m_Hide304s in the script for an example of controlling the behavior using a menu item.

    If you always want to return the same modified response, you don't need a script for that. Edit the response (either at a breakpoint or by using the "Unlock for Editing" command on the Web Session's context menu) then drag/drop the Session to Fiddler's AutoResponder tab to create a new rule that always plays back that response.

    To always respond with a script, make a rule like:

    MatchText: whatever 
    Action: *script:DoMagic  


    Save the rule. Click Rules > Customize Rules. Inside the Handlers class add the following code:
          
        static function DoMagic(oS: Session)
        {
            oS.utilCreateResponseAndBypassServer();
            oS.oResponse.headers.StatusDescription = "Magic!";
            oS.utilSetResponseBody("Some magic just happened to session #" + oS.id);
        }



    Regards,
    Eric Lawrence
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top