Opened 17 years ago

Closed 17 years ago

#3057 closed defect (fixed)

[patch] WSGI handler expects CONTENT_LENGTH to be always present

Reported by: Ivan Sagalaev <Maniac@…> 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)

3057.diff (729 bytes ) - added by Ivan Sagalaev <Maniac@…> 17 years ago.
Fix
3057.2.diff (903 bytes ) - added by Ivan Sagalaev <Maniac@…> 17 years ago.
Fixing empty string in Content-Length

Download all attachments as: .zip

Change History (9)

by Ivan Sagalaev <Maniac@…>, 17 years ago

Attachment: 3057.diff added

Fix

comment:1 by Ivan Sagalaev <Maniac@…>, 17 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 Adrian Holovaty, 17 years ago

Resolution: fixed
Status: newclosed

(In [4091]) Fixed #3057 -- Changed WSGI handler not to expect CONTENT_LENGTH. Thanks for the patch, Ivan Sagalaev

comment:3 by Barry Pederson <bp@…>, 17 years ago

Resolution: fixed
Status: closedreopened

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 Adrian Holovaty, 17 years ago

Resolution: fixed
Status: reopenedclosed

(In [4094]) Fixed #3057 -- Fixed typo in [4091]. Thanks for the heads-up, Barry Pederson

comment:5 by Ivan Sagalaev <Maniac@…>, 17 years ago

Cc: Maniac@… added
Resolution: fixed
Status: closedreopened

Greg Chapman in django-developers points out that CONTENT_LENGTH may be present but contain an empty string which than fails with ValueError.

by Ivan Sagalaev <Maniac@…>, 17 years ago

Attachment: 3057.2.diff added

Fixing empty string in Content-Length

comment:6 by glchapman42@…, 17 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 = ''

comment:7 by Adrian Holovaty, 17 years ago

Resolution: fixed
Status: reopenedclosed

Fixed in [4107].

Note: See TracTickets for help on using tickets.
Back to Top