1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import HTTP
import json
import config
def playout(filename):
return ["", [('Content-Type','text/html'), ("X-Accel-Redirect", filename)], None]
def home():
return ["", [('Content-Type','text/html'), ("Location", config.homepage)], "302 Home"]
def route(path, env, session, post):
if path[0] == "8cabc1fce52bcb565ae203267ce7e73f69a9272e":
return playout("interface/listing.htm")
if path[0] == "test":
return playout("interface/listing.htm")
# Default path
return home()
def handle_request(env, response):
path = env.get('PATH_INFO', '').lstrip('/').split('/')
post = {}
headers = []
# Read POST data
try:
content_length = int(env.get('CONTENT_LENGTH', '0'))
post_raw = env["wsgi.input"].read(content_length).decode('utf-8')
if env.get('CONTENT_TYPE', '') == "multipart/form-data":
post = HTTP.formdata(post_raw)
except ValueError as e:
post = None
# Route request
data, addtl_headers, code = route(path, env, session, post)
headers.extend(addtl_headers)
response(code if code else "200 OK", headers)
return [bytes(data)]
|