summaryrefslogtreecommitdiff
path: root/cgi-bin
diff options
context:
space:
mode:
authorjules <jules@okfoc.us>2014-11-26 23:08:21 -0500
committerjules <jules@okfoc.us>2014-11-26 23:08:21 -0500
commit29b84b37752ee80eac025fe53dcdc8de2bc9ff73 (patch)
tree1c2e2a9f62d1ef3b623ae9197a6c880879db74e7 /cgi-bin
parent983a3dac6cb7d04022ccb4a4c26892ef97c9d0b3 (diff)
jsonp support, possibly..
Diffstat (limited to 'cgi-bin')
-rwxr-xr-xcgi-bin/proxy16
1 files changed, 12 insertions, 4 deletions
diff --git a/cgi-bin/proxy b/cgi-bin/proxy
index 9c2ca3d..801e0f2 100755
--- a/cgi-bin/proxy
+++ b/cgi-bin/proxy
@@ -2,6 +2,7 @@
from os import environ as env
import urllib.request
+import json
import sys
def error():
@@ -9,18 +10,25 @@ def error():
print()
print("HELLO!")
-def proxy(url,ext):
+def proxy(url,ext,callback):
req = urllib.request.urlopen(url)
print("Content-type: image/" + ext)
print()
sys.stdout.flush()
- sys.stdout.buffer.write( req.read() )
+ if callback:
+ sys.stdout.buffer.write( callback + "('" )
+ sys.stdout.buffer.write( json.dump({ data: req.read() })
+ sys.stdout.buffer.write( callback + "')" )
+ else:
+ sys.stdout.buffer.write( req.read() )
-path = env['QUERY_STRING']
+qs = env['QUERY_STRING'].split('&callback=')
+path = qs[0]
+callback = qs[1]
ext = path[-3:].lower()
if path[0:4] == "http" and ext in ("gif","jpg","png","peg"):
- proxy(path,ext)
+ proxy(path,ext,callback)
else:
error()