4 """This is a blind proxy that we use to get around browser
5 restrictions that prevent the Javascript from loading pages not on the
6 same server as the Javascript. This has several problems: it's less
7 efficient, it might break some sites, and it's a security risk because
8 people can use this proxy to browse the web and possibly do bad stuff
9 with it. It only loads pages via http and https, but it can load any
10 content type. It supports GET and POST requests."""
16 # Designed to prevent Open Proxy type stuff.
18 allowedHosts = ['www.openlayers.org', 'openlayers.org',
19 'labs.metacarta.com', 'world.freemap.in',
20 'prototype.openmnnd.org', 'geo.openplans.org',
21 'sigma.openplans.org', 'demo.opengeo.org',
22 'www.openstreetmap.org', 'sample.avencia.com']
24 method = os.environ["REQUEST_METHOD"]
27 qs = os.environ["QUERY_STRING"]
32 url = "http://www.openlayers.org"
34 fs = cgi.FieldStorage()
35 url = fs.getvalue('url', "http://www.openlayers.org")
38 host = url.split("/")[2]
39 if allowedHosts and not host in allowedHosts:
40 print "Status: 502 Bad Gateway"
41 print "Content-Type: text/plain"
43 print "This proxy does not allow you to access that location (%s)." % (host,)
47 elif url.startswith("http://") or url.startswith("https://"):
50 length = int(os.environ["CONTENT_LENGTH"])
51 headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
52 body = sys.stdin.read(length)
53 r = urllib2.Request(url, body, headers)
54 y = urllib2.urlopen(r)
56 y = urllib2.urlopen(url)
58 # print content type header
60 if i.has_key("Content-Type"):
61 print "Content-Type: %s" % (i["Content-Type"])
63 print "Content-Type: text/plain"
70 print "Content-Type: text/plain"
72 print "Illegal request."
75 print "Status: 500 Unexpected Error"
76 print "Content-Type: text/plain"
78 print "Some unexpected error occurred. Error text was:", E