diff options
| author | jules <jules@okfoc.us> | 2015-02-23 14:06:54 -0500 |
|---|---|---|
| committer | jules <jules@okfoc.us> | 2015-02-23 14:06:54 -0500 |
| commit | 673f9b22840417c8de68e5311fb6dcb76b9b35ca (patch) | |
| tree | f9dbda0b1b0e6e9da9b3775b2d5a282c80c62af1 /cgi-bin/proxy | |
| parent | 7e21f72384f24621ad060fecc49cff186167f523 (diff) | |
| parent | d5886f67ee6edbafc759410e92917593dc9329a0 (diff) | |
Merge branch 'master' of lmno:dither
Diffstat (limited to 'cgi-bin/proxy')
| -rwxr-xr-x | cgi-bin/proxy | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/cgi-bin/proxy b/cgi-bin/proxy index 9c2ca3d..5e3539c 100755 --- a/cgi-bin/proxy +++ b/cgi-bin/proxy @@ -2,6 +2,8 @@ from os import environ as env import urllib.request +import base64 +import json import sys def error(): @@ -9,18 +11,30 @@ 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 != "": + print("Content-type: text/plain") + print() + sys.stdout.flush() + sys.stdout.buffer.write( bytes( callback + "(" + json.dumps( "".join(map(chr, base64.b64encode( req.read() )))) + ")" , 'utf-8')) + else: + print("Content-type: image/" + ext) + print() + sys.stdout.flush() + sys.stdout.buffer.write( req.read() ) + +qs = env['QUERY_STRING'].split('&callback=') +if len(qs) == 2: + callback = qs[1] +else: + callback = '' +path = qs[0] -path = env['QUERY_STRING'] 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() |
