Code

Ticket #8259: patch.diff

File patch.diff, 863 bytes (added by kevin, 6 years ago)

Treat Content-Length of None as if empty string

Line 
1Index: django/core/handlers/wsgi.py
2===================================================================
3--- django/core/handlers/wsgi.py        (revision 8472)
4+++ django/core/handlers/wsgi.py        (working copy)
5@@ -173,7 +173,9 @@
6             try:
7                 # CONTENT_LENGTH might be absent if POST doesn't have content at all (lighttpd)
8                 content_length = int(self.environ.get('CONTENT_LENGTH', 0))
9-            except ValueError: # if CONTENT_LENGTH was empty string or not an integer
10+            except (ValueError, TypeError):
11+                # If CONTENT_LENGTH was empty string, None or not an integer.
12+                # It ought not to be None, but that has been reported (see #8259) hence TypeError.
13                 content_length = 0
14             if content_length > 0:
15                 safe_copyfileobj(self.environ['wsgi.input'], buf,