Skip to content

Request.body hangs forever when no body is submitted #233

@Sirtea

Description

@Sirtea

Hi all,

I am making a really minimal API mongodb based. By chance, I have discovered a bug when reading request.body, that causes code to hang forever. I tried to reproduce the bare minimum to show the error, as stated here:

The application is really minimal, as follows (it has also a wsgiref.simple_server:make_server instance, but it's unimportant):

from webob.dec import wsgify
from webob import Response

@wsgify
def application(req):
    print dict((key, value) for key, value in req.environ.iteritems() if key.startswith('CON'))
    print repr(req.body)
    return Response(body='Hello world\n', content_type='text/plain', status=200)

And the "API" invocations is done via curl, as follows:

gerard@sirius:~/projects/test$ curl -i -X POST http://localhost:8080/ --data ''
HTTP/1.0 200 OK
Date: Tue, 08 Mar 2016 20:33:48 GMT
Server: WSGIServer/0.1 Python/2.7.9
Content-Type: text/plain; charset=UTF-8
Content-Length: 12

Hello world
gerard@sirius:~/projects/test$ curl -i -X POST http://localhost:8080/
(blocks forever)

During this two invocations, it's clear that reading req.body blocks everything, when CONTENT_LENGTH is '' instead of '0'.

gerard@sirius:~/projects/test$ ./a.py 
Listening on port 8080...
{'CONTENT_LENGTH': '0', 'CONTENT_TYPE': 'application/x-www-form-urlencoded'}
''
127.0.0.1 - - [08/Mar/2016 21:33:48] "POST / HTTP/1.1" 200 12
{'CONTENT_LENGTH': '', 'CONTENT_TYPE': 'text/plain'}
(blocks forever)

I'm really worried about this because body is out of my reach, depending on my users' good faith.

If it helps, the only module involved is WebOb==1.5.1, pip'ed from pypi

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions