In discussion with Jachym, Tim pointed out that he has already written a
proxy that supports post -- and his was more complete. Pull in Tim's. (This is from the wfsv sandbox.) Thanks, Tim. (See #991) git-svn-id: http://svn.openlayers.org/trunk/openlayers@4371 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+35
-24
@@ -9,24 +9,28 @@ people can use this proxy to browse the web and possibly do bad stuff
|
|||||||
with it. It only loads pages via http and https, but it can load any
|
with it. It only loads pages via http and https, but it can load any
|
||||||
content type. It supports GET and POST requests."""
|
content type. It supports GET and POST requests."""
|
||||||
|
|
||||||
import urllib
|
import urllib2
|
||||||
import cgi
|
import cgi
|
||||||
import os
|
import sys, os
|
||||||
import sys
|
|
||||||
|
|
||||||
# Designed to prevent Open Proxy type stuff.
|
# Designed to prevent Open Proxy type stuff.
|
||||||
|
|
||||||
allowedHosts = ['www.openlayers.org', 'openlayers.org',
|
allowedHosts = ['www.openlayers.org', 'openlayers.org',
|
||||||
'labs.metacarta.com', 'world.freemap.in',
|
'labs.metacarta.com', 'world.freemap.in',
|
||||||
'prototype.openmnnd.org']
|
'prototype.openmnnd.org', 'geo.openplans.org']
|
||||||
|
|
||||||
# HTTP GET
|
method = os.environ["REQUEST_METHOD"]
|
||||||
if os.getenv("REQUEST_METHOD") != "POST":
|
|
||||||
fs = cgi.FieldStorage()
|
if method == "POST":
|
||||||
url = fs.getvalue('url', "http://openlayers.org")
|
qs = os.environ["QUERY_STRING"]
|
||||||
# HTTP POST
|
d = cgi.parse_qs(qs)
|
||||||
|
if d.has_key("url"):
|
||||||
|
url = d["url"][0]
|
||||||
|
else:
|
||||||
|
url = "http://www.openlayers.org"
|
||||||
else:
|
else:
|
||||||
url = urllib.unquote(os.getenv("QUERY_STRING").split("=")[1])
|
fs = cgi.FieldStorage()
|
||||||
|
url = fs.getvalue('url', "http://www.openlayers.org")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
host = url.split("/")[2]
|
host = url.split("/")[2]
|
||||||
@@ -35,29 +39,36 @@ try:
|
|||||||
print "Content-Type: text/plain"
|
print "Content-Type: text/plain"
|
||||||
print
|
print
|
||||||
print "This proxy does not allow you to access that location."
|
print "This proxy does not allow you to access that location."
|
||||||
|
print
|
||||||
|
print os.environ
|
||||||
|
|
||||||
elif url.startswith("http://") or url.startswith("https://"):
|
elif url.startswith("http://") or url.startswith("https://"):
|
||||||
|
|
||||||
# HTTP GET
|
if method == "POST":
|
||||||
if os.getenv("REQUEST_METHOD") != "POST":
|
length = int(os.environ["CONTENT_LENGTH"])
|
||||||
y = urllib.urlopen(url)
|
headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
|
||||||
# HTTP POST
|
body = sys.stdin.read(length)
|
||||||
|
r = urllib2.Request(url, body, headers)
|
||||||
|
y = urllib2.urlopen(r)
|
||||||
else:
|
else:
|
||||||
y = urllib.urlopen(url,sys.stdin.read())
|
y = urllib2.urlopen(url)
|
||||||
|
|
||||||
headers = str(y.info()).split('\n')
|
# print content type header
|
||||||
for h in headers:
|
i = y.info()
|
||||||
if h.startswith("Content-Type:"):
|
if i.has_key("Content-Type"):
|
||||||
print h
|
print "Content-Type: %s" % (i["Content-Type"])
|
||||||
|
else:
|
||||||
|
print "Content-Type: text/plain"
|
||||||
print
|
print
|
||||||
|
|
||||||
print y.read()
|
print y.read()
|
||||||
|
|
||||||
y.close()
|
y.close()
|
||||||
else:
|
else:
|
||||||
print """Content-Type: text/plain
|
print "Content-Type: text/plain"
|
||||||
|
print
|
||||||
Illegal request."""
|
print "Illegal request."
|
||||||
|
|
||||||
except Exception, E:
|
except Exception, E:
|
||||||
print "Status: 500 Unexpected Error"
|
print "Status: 500 Unexpected Error"
|
||||||
print "Content-Type: text/plain"
|
print "Content-Type: text/plain"
|
||||||
|
|||||||
Reference in New Issue
Block a user