-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathwsgi.py
66 lines (43 loc) · 1.21 KB
/
wsgi.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import time
HEADERS = [('content-type', 'text/plain; charset=utf-8')]
BODY_BYTES_SHORT = b'Test'
BODY_BYTES_LONG = b'Test' * 20_000
BODY_STR_SHORT = 'Test'
BODY_STR_LONG = 'Test' * 20_000
def b_short(environ, proto):
proto('200 OK', HEADERS)
return [BODY_BYTES_SHORT]
def b_long(environ, proto):
proto('200 OK', HEADERS)
return [BODY_BYTES_LONG]
def s_short(environ, proto):
proto('200 OK', HEADERS)
return [BODY_STR_SHORT.encode('utf8')]
def s_long(environ, proto):
proto('200 OK', HEADERS)
return [BODY_STR_LONG.encode('utf8')]
def echo(environ, proto):
proto('200 OK', HEADERS)
return [environ['wsgi.input'].read()]
def io_builder(wait):
wait = wait / 1000
def io(environ, proto):
proto('200 OK', HEADERS)
time.sleep(wait)
return [BODY_BYTES_SHORT]
return io
def handle_404(environ, proto):
proto('404 NOT FOUND', HEADERS)
return [b'not found']
routes = {
'/b': b_short,
'/bb': b_long,
'/s': s_short,
'/ss': s_long,
'/echo': echo,
'/io10': io_builder(10),
'/io100': io_builder(100),
}
def app(environ, proto):
handler = routes.get(environ['PATH_INFO'], handle_404)
return handler(environ, proto)