Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#8259 closed (fixed)

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

Reported by: erny Owned by: Kevin McConnell
Component: HTTP handling Version: dev
Severity: Keywords: aug22sprint
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (1)

patch.diff (863 bytes ) - added by Kevin McConnell 16 years ago.
Treat Content-Length of None as if empty string

Download all attachments as: .zip

Change History (9)

comment:1 by Malcolm Tredinnick, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

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).

comment:2 by Graham Dumpleton, 16 years ago

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.

comment:3 by Kevin McConnell, 16 years ago

Owner: changed from nobody to Kevin McConnell
Status: newassigned

by Kevin McConnell, 16 years ago

Attachment: patch.diff added

Treat Content-Length of None as if empty string

comment:4 by Kevin McConnell, 16 years ago

Has patch: set

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.

comment:5 by Kevin McConnell, 16 years ago

Keywords: aug22sprint added

comment:6 by Malcolm Tredinnick, 16 years ago

@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.

comment:7 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: assignedclosed

(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.

comment:8 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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