Django

Code

Ticket #3057 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] WSGI handler expects CONTENT_LENGTH to be always present

Reported by: Ivan Sagalaev <Maniac@SoftwareManiacs.Org> Assigned to: adrian
Milestone: Component: Core framework
Version: Keywords:
Cc: Maniac@SoftwareManiacs.Org Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

3057.diff (0.7 kB) - added by Ivan Sagalaev <Maniac@SoftwareManiacs.Org> on 11/23/06 09:10:11.
Fix
3057.2.diff (0.9 kB) - added by Ivan Sagalaev <Maniac@SoftwareManiacs.Org> on 11/23/06 16:49:28.
Fixing empty string in Content-Length

Change History

11/23/06 09:10:11 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

  • attachment 3057.diff added.

Fix

11/23/06 09:11:22 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

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

11/23/06 11:06:11 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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

11/23/06 11:40:05 changed by Barry Pederson <bp@barryp.org>

  • status changed from closed to reopened.
  • resolution deleted.

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.

11/23/06 11:48:06 changed by adrian

  • status changed from reopened to closed.
  • resolution set to fixed.

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

11/23/06 16:43:45 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

  • cc set to Maniac@SoftwareManiacs.Org.
  • status changed from closed to reopened.
  • resolution deleted.

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

11/23/06 16:49:28 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

  • attachment 3057.2.diff added.

Fixing empty string in Content-Length

11/24/06 13:11:25 changed by glchapman42@gmail.com

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 = ''

11/26/06 17:53:16 changed by adrian

  • status changed from reopened to closed.
  • resolution set to fixed.

Fixed in [4107].


Add/Change #3057 ([patch] WSGI handler expects CONTENT_LENGTH to be always present)




Change Properties
Action