forked from squeaky-pl/japronto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.py
48 lines (33 loc) · 993 Bytes
/
dump.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
41
42
43
44
45
46
47
48
import os.path
import sys
import base64
import asyncio
from app import Application
def dump(request):
body = request.body
if body is not None:
body = base64.b64encode(body).decode('ascii')
result = {
"method": request.method,
"path": request.path,
"query_string": request.query_string,
"headers": request.headers,
"match_dict": request.match_dict,
"body": body,
"route": request.route.pattern
}
return request.Response(json=result)
async def adump(request):
sleep = float(request.query.get('sleep', 0))
await asyncio.sleep(sleep)
return dump(request)
app = Application()
r = app.get_router()
r.add_route('/dump/{p1}/{p2}', dump)
r.add_route('/dump1/{p1}/{p2}', dump)
r.add_route('/dump2/{p1}/{p2}', dump)
r.add_route('/async/dump/{p1}/{p2}', adump)
r.add_route('/async/dump1/{p1}/{p2}', adump)
r.add_route('/async/dump2/{p1}/{p2}', adump)
if __name__ == '__main__':
app.serve()