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:
+29
-13
@@ -18,20 +18,36 @@ import cgi
|
|||||||
fs = cgi.FieldStorage()
|
fs = cgi.FieldStorage()
|
||||||
url = fs.getvalue('url', "http://openlayers.org")
|
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')
|
elif url.startswith("http://") or url.startswith("https://"):
|
||||||
for h in headers:
|
|
||||||
if h.startswith("Content-Type:"):
|
|
||||||
print h
|
|
||||||
print
|
|
||||||
|
|
||||||
print y.read()
|
y = urllib.urlopen(url)
|
||||||
|
|
||||||
y.close()
|
headers = str(y.info()).split('\n')
|
||||||
else:
|
for h in headers:
|
||||||
print """Content-Type: text/plain
|
if h.startswith("Content-Type:"):
|
||||||
|
print h
|
||||||
|
print
|
||||||
|
|
||||||
|
print y.read()
|
||||||
|
|
||||||
|
y.close()
|
||||||
|
else:
|
||||||
|
print """Content-Type: text/plain
|
||||||
|
|
||||||
Illegal request."""
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user