Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Lib/cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,6 @@ def read_multi(self, environ, keep_blank_values, strict_parsing):
parser.feed(hdr_text.decode(self.encoding, self.errors))
headers = parser.close()

# Some clients add Content-Length for part headers, ignore them
if 'content-length' in headers:
del headers['content-length']

part = klass(self.fp, headers, ib, environ, keep_blank_values,
strict_parsing,self.limit-self.bytes_read,
self.encoding, self.errors)
Expand Down Expand Up @@ -818,7 +814,7 @@ def make_file(self):
which unlinks the temporary files you have created.

"""
if self._binary_file:
if self._binary_file or self.length >= 0:
return tempfile.TemporaryFile("wb+")
else:
return tempfile.TemporaryFile("w+",
Expand Down
15 changes: 14 additions & 1 deletion Lib/test/test_cgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,20 @@ def test_fieldstorage_part_content_length(self):
fs = cgi.FieldStorage(fp, environ=env, encoding="latin-1")
self.assertEqual(len(fs.list), 1)
self.assertEqual(fs.list[0].name, 'submit-name')
self.assertEqual(fs.list[0].value, 'Larry')
self.assertEqual(fs.list[0].value, b'Larry')

def test_fieldstorage_not_multipart(self):
POSTDATA = b'{"name": "Bert"}'

env = {
'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'text/plain',
'CONTENT_LENGTH': str(len(POSTDATA))
}
fp = BytesIO(POSTDATA)
fs = cgi.FieldStorage(fp, environ=env)
self.assertEqual(fs.list, None)
self.assertEqual(fs.value, b'{"name": "Bert"}')

def test_fieldstorage_as_context_manager(self):
fp = BytesIO(b'x' * 10)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix issue in cgi.py sending requests with Content-Length but without
Content-Disposition headers, also choosing between creating files in text or
binary mode.