Django

Code

Ticket #8259 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

core/handlers/wsgi.py: raises TypeError in _get_raw_post_data if CONTENT_LENGTH is empty.

Reported by: erny Assigned to: kevin
Milestone: 1.0 Component: HTTP handling
Version: SVN Keywords: aug22sprint
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

  • write a view which gets raw_post_data from request.
  • run development server
  • use pycurl or other client which can send an empty Content-length header.
  • raises TypeError? near: core/handlers/wsgi.py:175
          content_length = int(self.environ.get('CONTENT_LENGTH', 0))
    
  • the problem is that CONTENT_LENGTH is None and type(None) -> TypeError?

I vave to further investigate this.

Attachments

patch.diff (0.8 kB) - added by kevin on 08/22/08 17:57:59.
Treat Content-Length of None as if empty string

Change History

08/12/08 09:46:10 changed by mtredinnick

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • milestone set to 1.0.

That sounds quite believable. I remember having to work around that None vs. missing entirely issue in some other places in the handlers. That single line should be split into two phases: get the environment variable and, if it's not "true", set it to 0.

Zero length posts are quite valid (since it could be automatically creating a new resource).

08/13/08 06:38:40 changed by grahamd

A correctly implemented WSGI server should however never be passing CONTENT_LENGTH with value None in WSGI environment.

WSGI PEP says:

"""CONTENT_LENGTH The contents of any Content-Length fields in the HTTP request. May be empty or absent."""

Prior to that also says:

"""The following variables must be present, unless their value would be an empty string, in which case they may be omitted, except as otherwise noted below."""

One trap in this is that it suggested that CONTENT_LENGTH can be an empty string and only that it 'may' be omitted in that circumstances, but not required.

Thus, are you sure problem is that it is coming through as None, if it is, then underlying WSGI server code is wrong. Separately though, seems the conversion to integer should cope with an empty string, which it isn't.

So perhaps two issues here.

08/22/08 17:43:05 changed by kevin

  • owner changed from nobody to kevin.
  • status changed from new to assigned.

08/22/08 17:57:59 changed by kevin

  • attachment patch.diff added.

Treat Content-Length of None as if empty string

08/22/08 17:59:00 changed by kevin

  • has_patch set to 1.

I personally couldn't reproduce this problem. And as Graham explained, CONTENT_LENGTH should never have value None anyway.

For the sake of safety & clarity, the patch simply catches TypeError?, treating the None the same way as an empty string.

08/22/08 17:59:33 changed by kevin

  • keywords set to aug22sprint.

08/23/08 13:02:03 changed by mtredinnick

@kevin: given this patch and a couple of other of yours we've committed / will commit, feel free to open a ticket with a patch to AUTHORS for your name.

08/23/08 13:08:30 changed by mtredinnick

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

(In [8495]) Fixed #8259 -- Handle an error situation that we should never see, but still occurs for some reason (be liberal in what you accept, and all that). Patch from kevin.


Add/Change #8259 (core/handlers/wsgi.py: raises TypeError in _get_raw_post_data if CONTENT_LENGTH is empty.)




Change Properties
Action