3 Replies Latest reply on Dec 7, 2010 6:07 AM by Mihai Balan

    Air Web Proxy


      Is it possible to create a web proxy in Air that can listen and reroute requests as needed?  The purpose of such a proxy would be to cache requests made via HTMLLoader.  Basically, I'd like a proxy that can monitor and download (cache) all requests made inside an HTMLLoader session, especially if the user clicks a link that was not originally specified in the HTMLLoader.load(url) command, and send the user to the local copy if the live server becomes unavailable.

        • 1. Re: Air Web Proxy
          ApolloX2 Level 1

          I noticed I can detect when the user has clicked a page in the browser by adding the locationChange listener such as:


          var online:Boolean = true;

          var htmlLoader:HTMLLoader = new HTMLLoader();



          private function pageChanged(event:Event):void {

               if(online) {

                    // Save copy of page to disk


               } else {

                    // Load cached copy from disk (if available)

                    htmlLoader.load(new URLRequest(...));




          That, along with a Socket monitor to update "online", would allow me to simulate a web proxy for the URL itself, but not any of its assets.  In other words, the mechanism about would work except that the images/css/Javascript on individual pages would be unavailable.


          Any tips?  Either to download the assets of a web page *or* create a true web proxy?  One of the problems of this technique is that the event is fired after the page has been called, not before.

          • 2. Re: Air Web Proxy
            ApolloX2 Level 1

            Seriosuly, no one has ever set up a web cache with HTMLLoader?

            • 3. Re: Air Web Proxy
              Mihai Balan Adobe Employee

              Hi ApolloX2,

              First of all, a few thoughts about the problem you're facing here


              1. Actually deciding if the server is not available is not an easy task: a server can be slow to process a request and send the answer but still be available. On the other hand, the server can answer, but return an error (anything from "410 Gone" to "500 Internal Server Error" to redirects). Did you consider all these cases?


              2. Detecting when/if all the resources on a page have been loaded is another hard to solve problem: there's no event on the HTMLLoader to signal when *all* content was successfully loaded, and the matter is even more complicated when you consider dynamically generated/loaded content via JavaScript/AJAX.


              Of course, things can be simplyfied if you don't want to load "free-form" (arbitrary) web content but rather your application will load only content with a previously known structure/in a previously known setting. Either way, you'll still have to manually identify the resources you want to save and save them.


              If you have some prior info about what you're going to display (and save), you could parse the HTML loaded inside the HTMLLoader. The HTMLLoader object exposes the DOM nodes as dynamic properties. You can take a look at how that's done inside the AIRIntrospector framework that's shipped with the AIR SDK. You can find the source in SDK_PATH/frameworks/libs/air/AIRIntrospector.js .


              Hope this helps,