#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)
Change History (9)
comment:1 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 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 , 16 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 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 , 16 years ago
Keywords: | aug22sprint added |
---|
comment:6 by , 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 , 16 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
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).