xref: /unit/test/python/delayed/wsgi.py (revision 1445:5a603827ec10)
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        time.sleep(delay)
15        return []
16
17    step = int(len(body) / parts)
18    for i in range(0, len(body), step):
19        try:
20            write(body[i : i + step])
21        except:
22            break
23
24        time.sleep(delay)
25
26    return []
27