Opened 7 years ago

Closed 7 years ago

Last modified 4 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
Component: HTTP handling Version: master
Severity: Keywords: aug22sprint
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 7 years ago.
Treat Content-Length of None as if empty string

Download all attachments as: .zip

Change History (9)

comment:1 Changed 7 years ago by mtredinnick

  • milestone set to 1.0
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 7 years ago 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.

comment:3 Changed 7 years ago by kevin

  • Owner changed from nobody to kevin
  • Status changed from new to assigned

Changed 7 years ago by kevin

Treat Content-Length of None as if empty string

comment:4 Changed 7 years ago by kevin

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

  • Keywords aug22sprint added

comment:6 Changed 7 years ago 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.

comment:7 Changed 7 years ago by mtredinnick

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

(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 Changed 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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