Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No response is returned when requesting POST in 2.0.0a1 version #1470

Closed
shimakaze-git opened this issue Mar 4, 2019 · 3 comments
Closed

Comments

@shimakaze-git
Copy link

shimakaze-git commented Mar 4, 2019

Hi, I might have found a bug on 2.0.0a1 version.

I tried this code on 2.0.0a1 version.
but, Processing stops on 'req.stream.read()', there is no response.

import falcon

class SampleResource(object):
    def on_post(self, req, resp):
        data = req.stream.read()
        return {'status': 'ok'}

app = falcon.API()
app.add_route("/", SampleResource())

if __name__ == "__main__":
    from wsgiref import simple_server
    httpd = simple_server.make_server("127.0.0.1", 8000, app)
    httpd.serve_forever()

I executed this curl command.but, No response is returned.

curl -i -XPOST \                                                   23:10:34
         -H "Accept:application/json" \
         -H "Content-Type:application/json" \
     "http://127.0.0.1:8000" \
     -d '{"data": 2}'
@vytas7
Copy link
Member

vytas7 commented Mar 4, 2019

Hi @shimakaze-git !
I would like to claim that this is not a bug, but a breaking change in Falcon 2.0.
For performance reasons, we are no longer wrapping req.stream with BoundedStream. BoundedStream helps to normalize the behaviour across various WSGI server implementations, including somewhat glitchy ones.
This is documented together with other breaking changes, see the note about falcon.Request.stream.

The wrapped stream is available as resp.bounded_stream. I have modified your example to get it to work the way you may have expected:

@@ -2,8 +2,8 @@
 
 class SampleResource(object):
     def on_post(self, req, resp):
-        data = req.stream.read()
-        return {'status': 'ok'}
+        data = req.bounded_stream.read()
+        resp.media = {'status': 'ok'}
 
 app = falcon.API()
 app.add_route("/", SampleResource())

Let us know if you experience the documentation note as unclear though! We can improve it for the final release if this is the case.

Kindly,
Vytas

@shimakaze-git
Copy link
Author

@vytas7
Thank you for teaching me.I'll read the document properly.

@vytas7
Copy link
Member

vytas7 commented Mar 6, 2019

No worries, let us know if you find any deficiencies in the documentation, we'll try to improve!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants