Code

Opened 7 years ago

Closed 7 years ago

#3057 closed defect (fixed)

[patch] WSGI handler expects CONTENT_LENGTH to be always present

Reported by: Ivan Sagalaev <Maniac@…> Owned by: adrian
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: UI/UX:

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@…> 7 years ago.
Fix
3057.2.diff (903 bytes) - added by Ivan Sagalaev <Maniac@…> 7 years ago.
Fixing empty string in Content-Length

Download all attachments as: .zip

Change History (9)

Changed 7 years ago by Ivan Sagalaev <Maniac@…>

Fix

comment:1 Changed 7 years ago by Ivan Sagalaev <Maniac@…>

  • Summary changed from WSGI handle expects CONTENT_LENGTH to be always present to [patch] WSGI handler expects CONTENT_LENGTH to be always present

comment:2 Changed 7 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:3 Changed 7 years ago by Barry Pederson <bp@…>

  • Resolution fixed deleted
  • Status changed from closed to 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 Changed 7 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

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

comment:5 Changed 7 years ago by Ivan Sagalaev <Maniac@…>

  • Cc Maniac@… added
  • Resolution fixed deleted
  • Status changed from closed to reopened

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

Changed 7 years ago by Ivan Sagalaev <Maniac@…>

Fixing empty string in Content-Length

comment:6 Changed 7 years ago by glchapman42@…

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 Changed 7 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed in [4107].

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.