AJAX Proxy 0.1

If you’ve read any of the posts I’ve been dumping here, you’ll know I’m critical of the way AJAX is frequently being used on the grounds that the network / server (and their inherant instability) aren’t being considered. Specifically have the feeling alot of AJAX development is happening @localhost so these problems simply aren’t showing up.

Enter AJAX Proxy, which is meant as a tool to simulate network / server delays by sitting between your browser and your web server and delaying things.

The first version is up here and currently in very hacky form. It’s based on HTTP Debugging Proxy which in turn was based on TinyHTTPProxy. To get it to run on Windows, got some help from rgutils.async, which I used to replace the signal calls. Also, with a little hacking, got it to support a proxy itself (if you’re behind one) – see globals at start of ajaxproxy.py.

To run it, unzip the source somewhere, make sure you have Python installed then from the command line;

[code]
$ ajaxproxy.py 8080
[/code]

The argument is the port number it should run on (defaults to port 8000).

You then need to reconfigure your browser to use it as a proxy server (Firefox > Tools > Options > Connection Settings > Manual Configuration: http proxy = localhost, port = whatever port you used). Also make sure localhost (if that’s where you server is) is not listed in the “No Proxy For” field.

If you now make a request to localhost, you should see the request and response headers logged to your command prompt (TODO: extend this logging to include the payloads)

By default it won’t interrupt anything. To get it to delay / interrupt the request or response, right now you need to hack the source code (TODO: mini language to make this easier). In ajaxproxy.py, check out the following functions;

[code lang=”python”]
def beforeRequest():
“””This function is executed before the request happens”””

#Constant sleep
#time.sleep(2)

# Random sleep
# r = random.Random(time.time())
# time.sleep(r.choice((0,5)))”””

# return 0 # Request never happens
return 1

def afterResponse():
“””This function is executed after response is received
but before it’s given to the browser”””

#Constant sleep
#time.sleep(2)

# Random sleep
# r = random.Random(time.time())
# time.sleep(r.choice((0,5)))”””

# return 0 # Response not sent to browser
return 1
[/code]

It doesn’t support HTTPS (or FTP or anything but plain old HTTP) but if you’re confident to hack a little python, it’s hopefully good enough to get a feeling for what your AJAX app is like when delays start happening.

More as it evolves…

3 Responses to AJAX Proxy 0.1
  1. mike
    November 11, 2008 | 3:47 pm

    The Ajax Blog pointed to a first release of an AJAX based proxy, a tool to simulate network / server delays by sitting between your browser and your web server and delaying things.

  2. Curiosity is bliss
    September 21, 2005 | 5:43 pm

    XmlHttpRequest – Add Latency

    I found about Harry Fuecks’ AJAX Proxy thru this post on AJAX apps and latency. Network latency is indeed very important to take in account when building a responsive web application, and its easy for developpers using their local webserver to overloo…

  3. AJAX Proxy 0.2 - Ajax Blog
    August 8, 2005 | 9:27 pm

    […] e POST body (duh). The basic instructions on setting up Python are the same, as described earlier. Configuration of the script has now changed – at the end of the script you would […]