-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
40 lines (30 loc) · 804 Bytes
/
run.py
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
39
40
from gevent import monkey, pywsgi
monkey.patch_all()
import falcon
import re
import logging
logging.basicConfig(level=logging.DEBUG)
from pybase64 import b64decode
from requests import Session
from urllib.parse import urlparse, urljoin
from handlers import handlers
from consts import Constant
from pools import pools
def on_request(req, res):
path = req.path[1:]
for ext in Constant.EXTS:
if path.endswith(ext):
payload = path[:-len(ext)] + '==='
url = b64decode(payload)
parsed_url = urlparse(url)
handlers[ext](url, res)
break
else:
res.status = '400'
res.body = 'NG'
app = falcon.App()
app.add_sink(on_request, '/')
if __name__ == '__main__':
port = 8000
server = pywsgi.WSGIServer(("localhost", port), app)
server.serve_forever()