Opened 19 years ago
Closed 19 years ago
#3057 closed defect (fixed)
[patch] WSGI handler expects CONTENT_LENGTH to be always present
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Core (Other) | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Maniac@… | Triage Stage: | Unreviewed |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
CONTENT_LENGTH may be absent if a POST request doesn't have a content at all (at least with lighttpd). This is BTW not so rare thing especially in ajax stuff: when calling XmlHttpRequest.send() without data for POST requests Firefox doesn't include nor data, neither Content-Length. May be others too.
Fix is trivial, patch follows.
Attachments (2)
Change History (9)
by , 19 years ago
comment:1 by , 19 years ago
| Summary: | WSGI handle expects CONTENT_LENGTH to be always present → [patch] WSGI handler expects CONTENT_LENGTH to be always present |
|---|
comment:2 by , 19 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:3 by , 19 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
It looks like that patch didn't go in correctly, it shows
content_length = int(self.environ.get('CONTENT_LENGTH', ))
missing the zero as the second parameter to the get() call.
comment:4 by , 19 years ago
| Resolution: | → fixed |
|---|---|
| Status: | reopened → closed |
comment:5 by , 19 years ago
| Cc: | added |
|---|---|
| Resolution: | fixed |
| Status: | closed → reopened |
Greg Chapman in django-developers points out that CONTENT_LENGTH may be present but contain an empty string which than fails with ValueError.
comment:6 by , 19 years ago
Sorry to comment on a closed report, but I've I've been getting an apparent blocked socket during the call to safe_copyfileobj when content_length == 0 (that is, the browser never receives a response from Django). (By the way, I'm using Python 2.5, so I downloaded the development version. Also, operating system is Windows XP and I'm just using the built-in HTTP server to work through the Tutorial). FWIW, extending the _get_raw_post_data patch to have the following has removed the block:
try:
# CONTENT_LENGTH might be absent if POST doesn't have content at all (lighttpd)
content_length = int(self.environ.get('CONTENT_LENGTH', 0))
except ValueError:
content_length = 0
if content_length:
safe_copyfileobj(self.environ['wsgi.input'], buf, size=content_length)
self._raw_post_data = buf.getvalue()
else:
self._raw_post_data = ''
Fix