Friday, July 13, 2012

Modifying an internet request with a proxy rule *(fiddler rule)


I was approached to help increase the usability of a script a friend of mine wrote. This script he wrote manipulates the page and you have to put it into the address bar after you have loaded your page.
Of course you can plug this into a bookmark and place it in your links/favorites/bookmark/etc tool bar. This feels clumsy. So I said: "Why not load the script into the page via Fiddler?"  So here is how you hook a script into a page you want to add something to.
  • Download & install Fiddler if you don't have it already. You may have to configure your browsers so that fiddler catches the traffic coming from them. Everything you need for this is on the site. I also recommend using the rule editor app that is available too, its much easier then any js editor. Including notepad.
  • Open Fiddler and go to Rules -> Custom Rules (Ctrl+R). This will load a js file that it used to manage the rules.
  • Find the method: "static function OnBeforeResponse(oSession: Session)". You will be adding to this one.
  • You can either tag your script to any site you want or you can tag it to just specific sites. For the example its going to connect only to a single site. "forums.xna.com"
  • This just intercepts the header that contains HTML and is coming from the "forums.xna.com" site. Regardless of the protocol used to request the file. After it finds the appropriate header it then takes the header, decodes it so it can find the ending body tag, append our script tag. The browser then receives the modified version of the HTML content and renders it up for you.
  • Next and final step to make this glorious script tag work for you is to set up an auto responder.
  • If enable autoresponders checkbox isn't checked do so now, or this won't work at all for you. Now the meat. Click "add" and a new pair of fields will show up. At the bottom you will see the text fields become enabled.
  • Enter the following in the left side: "/proxyasset/bokistool.js". This is the partial address that is in the script tag.
  • The right side you have a few options. Let's save this file to your computer. And browse to where you saved your file.  NOTE: this field also takes URLs so you can host the file somewhere so you can set this up for multiple systems and all you have to do is set up the rules and auto-responders.
  • Click SAVE.
  • Your done. Go reload the page and you should be boki-trolling the forums to your delight.
Here is the code boki had put together, and here is the file version I have. I am not responsible for any trouble from this code, nor will I take responsibility for all the enjoyment you will get from running it. That is all for boki. If you happen to know how to make fiddler run an auto-responder via the rules page please let me know. I was unable to figure that one out.
/proxyasset/bokistool.js

No comments:

Ajax Lesson

NOTE : This lesson uses jQuery as the interface for basic AJAX work. By no means is AJAX a product of jQuery and you do not need jQuery to ...