xref: /unit/test/python/delayed/wsgi.py (revision 1274:57f97f73eab7)
1import time
2
3
4def application(environ, start_response):
5    parts = int(environ.get('HTTP_X_PARTS', 1))
6    delay = int(environ.get('HTTP_X_DELAY', 0))
7
8    content_length = int(environ.get('CONTENT_LENGTH', 0))
9    body = bytes(environ['wsgi.input'].read(content_length))
10
11    write = start_response('200', [('Content-Length', str(len(body)))])
12
13    if not body:
14        return []
15
16    step = int(len(body) / parts)
17    for i in range(0, len(body), step):
18        try:
19            write(body[i : i + step])
20        except:
21            break
22
23        time.sleep(delay)
24
25    return []
26