Tests: added test for uploading files with SSL.

* * *
[mq]: multipart
This commit is contained in:
Tiago Natel de Moura
2020-02-05 13:29:41 +00:00
parent d3e218a8c3
commit 12e15ba43b
2 changed files with 49 additions and 0 deletions

View File

@@ -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