Code

Ticket #3496: wsgi_patch2.diff

File wsgi_patch2.diff, 1.2 KB (added by cephelo@…, 7 years ago)

Patch that applies cleanly against trunk

Line 
1Index: django/core/handlers/wsgi.py
2===================================================================
3--- django/core/handlers/wsgi.py        (revision 4490)
4+++ django/core/handlers/wsgi.py        (working copy)
5@@ -160,10 +160,19 @@
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+                has_content_length = True
10             except ValueError: # if CONTENT_LENGTH was empty string or not an integer
11                 content_length = 0
12-            safe_copyfileobj(self.environ['wsgi.input'], buf, size=content_length)
13-            self._raw_post_data = buf.getvalue()
14+                has_content_length = False
15+
16+            if has_content_length and content_length == 0:
17+                # Empty HTML forms do post a content length, but with a length of 0.
18+                # Socket read doesn't return with a size of 0. See #3496.
19+                pass
20+            else:
21+                safe_copyfileobj(self.environ['wsgi.input'], buf, size=content_length)
22+
23+            self._raw_post_data = buf.getvalue()
24             buf.close()
25             return self._raw_post_data
26