Commit changes to proxy script. Specifically:

* add allowedHosts.
 * Wrap all code in a try/except in case something breaks


git-svn-id: http://svn.openlayers.org/trunk/openlayers@205 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-05-20 03:29:43 +00:00
parent 563b828ede
commit 0e011e4584

View File

@@ -18,20 +18,36 @@ import cgi
fs = cgi.FieldStorage()
url = fs.getvalue('url', "http://openlayers.org")
if url.startswith("http://") or url.startswith("https://"):
allowedHosts = ['www.openlayers.org', 'openlayers.org', 'octo.metacarta.com']
allowedHosts = object()
host = url.split("/")[2]
y = urllib.urlopen(url)
try:
if allowedHosts and not host in allowedHosts:
print "Status: 502 Bad Gateway"
print "Content-Type: text/plain"
print
print "This proxy does not allow you to access that location."
headers = str(y.info()).split('\n')
for h in headers:
if h.startswith("Content-Type:"):
print h
print
elif url.startswith("http://") or url.startswith("https://"):
print y.read()
y.close()
else:
print """Content-Type: text/plain
y = urllib.urlopen(url)
headers = str(y.info()).split('\n')
for h in headers:
if h.startswith("Content-Type:"):
print h
print
print y.read()
y.close()
else:
print """Content-Type: text/plain
Illegal request."""
except Exception, E:
print "Status: 500 Unexpected Error"
print "Content-Type: text/plain"
print
print "Some unexpected error occurred. Error text was:", E