mirror of
https://github.com/tenox7/wrp.git
synced 2024-11-24 22:30:58 +00:00
Adds support for returning erors and non-HTML pages as is. Fixes #18
This commit is contained in:
parent
4fefe187cd
commit
100ab83720
28
wrp.py
28
wrp.py
@ -626,7 +626,6 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
|
||||
gif_re = re.match(r"http://(wrp-\d+\.gif).*", req_url)
|
||||
map_re = re.match(r"http://(wrp-\d+\.map).*?(\d+),(\d+)", req_url)
|
||||
ico_re = re.match(r"http://.+\.ico", req_url)
|
||||
jpg_re = re.match(r"http://(wrp-\d+\.jpg).*", req_url)
|
||||
|
||||
# Serve Rendered GIF
|
||||
@ -691,14 +690,24 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
httpout.write("<HTML><BODY><A HREF=\"%s\">%s</A></BODY></HTML>\n"
|
||||
% (goto_url, goto_url))
|
||||
|
||||
# ICO files, WebKit crashes on these
|
||||
elif ico_re:
|
||||
self.send_error(415, "ICO not supported")
|
||||
self.end_headers()
|
||||
|
||||
# Process a web page request and generate image
|
||||
else:
|
||||
print ">>> URL request... " + req_url
|
||||
|
||||
if req_url == "http://wrp.stop/" or req_url == "http://www.wrp.stop/":
|
||||
REQ.put((httpout, req_url, "", ""))
|
||||
RESP.get()
|
||||
else:
|
||||
reqst = urllib.urlopen(req_url)
|
||||
|
||||
if reqst.info().type == "text/html" or reqst.info().type == "application/xhtml+xml":
|
||||
# If an error occurs, send error headers to the requester
|
||||
if reqst.getcode() >= 400:
|
||||
self.send_response(reqst.getcode())
|
||||
for hdr in reqst.info():
|
||||
self.send_header(hdr, reqst.info()[hdr])
|
||||
self.end_headers()
|
||||
else:
|
||||
self.send_response(200, 'OK')
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
@ -723,6 +732,13 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||
REQ.put((httpout, req_url, "wrp-%s.gif" % (rnd), "wrp-%s.map" % (rnd)))
|
||||
# Wait for completition
|
||||
RESP.get()
|
||||
# If the requested file is not HTML or XHTML, just return it as is.
|
||||
else:
|
||||
self.send_response(reqst.getcode())
|
||||
for hdr in reqst.info():
|
||||
self.send_header(hdr, reqst.info()[hdr])
|
||||
self.end_headers()
|
||||
httpout.write(reqst.read())
|
||||
|
||||
def run_proxy():
|
||||
httpd = SocketServer.TCPServer(('', PORT), Proxy)
|
||||
|
Loading…
Reference in New Issue
Block a user