Ticket #366 (closed defect: worksforme)

Opened 3 years ago

Last modified 2 years ago

[PATCH] WebOb should leave req.body as is after parsing POST body

Reported by: wangchun Owned by: ianb
Priority: normal Milestone: 1.4.1
Component: webob Version: svn-trunk
Severity: normal Keywords:
Cc:

Description

For an empty Content-Type, req.body returns empty string (v0.9.6) or raises an error (trunk) after req.POST is called.

For Content-Type == application/x-www-form-urlencoded:

import webob
from StringIO import StringIO

body = 'HELLO, WORLD!'

environ = {
    'REQUEST_METHOD': 'POST',
    'CONTENT_TYPE': 'application/x-www-form-urlencoded',
    'CONTENT_LENGTH': str(len(body)),
    'wsgi.input': StringIO(body),
}

req = webob.Request(environ)
print req.body
print req.POST
print req.body
macbook:~/tmp$ python test.py
HELLO, WORLD!
MultiDict([('HELLO, WORLD!', '')])
HELLO%2C+WORLD%21=
macbook:~$ 

Attachments

366.diff Download (1.0 KB) - added by wangchun 3 years ago.
366.2.diff Download (1.0 KB) - added by wangchun 3 years ago.
also for req.body_file

Change History

Changed 3 years ago by wangchun

Changed 3 years ago by wangchun

  • summary changed from WebOb should leave req.body as is after parsing POST body to [PATCH] WebOb should leave req.body as is after parsing POST body

Changed 3 years ago by wangchun

also for req.body_file

Changed 2 years ago by maluke

  • status changed from new to closed
  • resolution set to worksforme
  • accessing .POST ends up normalizing the .body, so that will not be changed
  • if content_type is not form-encoded, .POST does not corrupt .body in any way. if it does for you, please add a test case.
Note: See TracTickets for help on using tickets.