diff options
author | Andrei Belov <defan@nginx.com> | 2020-02-06 18:25:25 +0300 |
---|---|---|
committer | Andrei Belov <defan@nginx.com> | 2020-02-06 18:25:25 +0300 |
commit | 2dc01938cf02cc05b41a09e618f712129c4cdf91 (patch) | |
tree | 556dd40a0ec8c194774d53eed9ff62ed1d25ee7c /test/python/upload/wsgi.py | |
parent | 477a58e14010ab14d6ab453860b360cf806f5012 (diff) | |
parent | 6e19090736612b39d4c5d0836d7df0722b8955e7 (diff) | |
download | unit-2dc01938cf02cc05b41a09e618f712129c4cdf91.tar.gz unit-2dc01938cf02cc05b41a09e618f712129c4cdf91.tar.bz2 |
Merged with the default branch.1.15.0-1
Diffstat (limited to 'test/python/upload/wsgi.py')
-rw-r--r-- | test/python/upload/wsgi.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/python/upload/wsgi.py b/test/python/upload/wsgi.py new file mode 100644 index 00000000..37ee89eb --- /dev/null +++ b/test/python/upload/wsgi.py @@ -0,0 +1,27 @@ +from tempfile import TemporaryFile +import os, cgi + +def read(environ): + length = int(environ.get('CONTENT_LENGTH', 0)) + + body = TemporaryFile(mode='w+b') + body.write(bytes(environ['wsgi.input'].read(length))) + body.seek(0) + + environ['wsgi.input'] = body + return body + +def application(environ, start_response): + file = read(environ) + + form = cgi.FieldStorage(fp=file, environ=environ, keep_blank_values=True) + + filename = form['file'].filename + data = filename.encode() + form['file'].file.read() + + start_response('200 OK', [ + ('Content-Type', 'text/plain'), + ('Content-Length', str(len(data))), + ]) + + return data |