#!/usr/local/bin/python """ sample implementation of a service that supports HTTP Response Bouncing """ ############################################################################### # ############################################################################### import time from cgi import FieldStorage from os import environ from urllib import quote ############################################################################### # ############################################################################### RESPONSE = """\ Bounce %f! \ """%(time.time()) ############################################################################### # ############################################################################### if __name__ == "__main__": try: bounce_url = environ["HTTP_BOUNCE_TO"] except KeyError: try: bounce_url = FieldStorage()["__bounce_to"].value except KeyError: bounce_url = None if bounce_url: bounce_url = """\ %s?status=200&type=text/xml&content=%s\ """%(bounce_url, quote(RESPONSE)) print """\ Location: %(bounce_url)s Status: 303 """%locals() else: print """\ Content-Type: text/xml Content-Length: %d %s"""%(len(RESPONSE), RESPONSE)