OLD | NEW |
(Empty) | |
| 1 import base64 |
| 2 import json |
| 3 |
| 4 def main(request, response): |
| 5 headers = [] |
| 6 headers.append(('X-ServiceWorker-ServerHeader', 'SetInTheServer')) |
| 7 |
| 8 if "ACAOrigin" in request.GET: |
| 9 for item in request.GET["ACAOrigin"].split(","): |
| 10 headers.append(("Access-Control-Allow-Origin", item)) |
| 11 |
| 12 for suffix in ["Headers", "Methods", "Credentials"]: |
| 13 query = "ACA%s" % suffix |
| 14 header = "Access-Control-Allow-%s" % suffix |
| 15 if query in request.GET: |
| 16 headers.append((header, request.GET[query])) |
| 17 |
| 18 if "ACEHeaders" in request.GET: |
| 19 headers.append(("Access-Control-Expose-Headers", request.GET[query])) |
| 20 |
| 21 if ("Auth" in request.GET and not request.auth.username) or "AuthFail" in re
quest.GET: |
| 22 status = 401 |
| 23 headers.append(('WWW-Authenticate', 'Basic realm="Restricted"')) |
| 24 body = 'Authentication canceled' |
| 25 return status, headers, body |
| 26 |
| 27 if "PNGIMAGE" in request.GET: |
| 28 headers.append(("Content-Type", "image/png")) |
| 29 body = base64.decodestring("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9h
AAAAAXNSR0IArs4c6QAAAARnQU1B" |
| 30 "AACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAh
SURBVDhPY3wro/KfgQLABKXJBqMG" |
| 31 "jBoAAqMGDLwBDAwAEsoCTFWunmQAAAAASUVORK5CYII=
") |
| 32 return headers, body |
| 33 |
| 34 |
| 35 username = request.auth.username if request.auth.username else "undefined" |
| 36 password = request.auth.password if request.auth.username else "undefined" |
| 37 cookie = request.cookies['cookie'].value if 'cookie' in request.cookies else
"undefined" |
| 38 |
| 39 files = [] |
| 40 for key, values in request.POST.iteritems(): |
| 41 assert len(values) == 1 |
| 42 value = values[0] |
| 43 if not hasattr(value, "file"): |
| 44 continue |
| 45 data = value.file.read() |
| 46 files.append({"key": key, |
| 47 "name": value.file.name, |
| 48 "type": value.type, |
| 49 "error": 0, #TODO, |
| 50 "size": len(data), |
| 51 "content": data}) |
| 52 |
| 53 get_data = {key:request.GET[key] for key,value in request.GET.iteritems()} |
| 54 post_data = {key:request.POST[key] for key,value in request.POST.iteritems() |
| 55 if not hasattr(request.POST[key], "file")} |
| 56 headers_data = {key:request.headers[key] for key,value in request.headers.it
eritems()} |
| 57 |
| 58 data = {"jsonpResult": "success", |
| 59 "method": request.method, |
| 60 "headers": headers_data, |
| 61 "body": request.body, |
| 62 "files": files, |
| 63 "GET": get_data, |
| 64 "POST": post_data, |
| 65 "username": username, |
| 66 "password": password, |
| 67 "cookie": cookie} |
| 68 |
| 69 return headers, "report( %s )" % json.dumps(data) |
OLD | NEW |