Skip to content

Commit

Permalink
Merge pull request #477 from suola/falcon-parser-wsgi-ref-read-requir…
Browse files Browse the repository at this point in the history
…es-argument

stdlib `wsgiref` requires argument for `read()`
  • Loading branch information
lafrech committed Feb 25, 2020
2 parents 2f8b0d2 + 9b86165 commit 7ccb1ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ Contributors (chronological)
* `@dodumosu <https://github.com/dodumosu>`_
* Nate Dellinger `@Nateyo <https://github.com/Nateyo>`_
* Karthikeyan Singaravelan `@tirkarthi <https://github.com/tirkarthi>`_
* Sami Salonen `@suola <https://github.com/suola>`_
2 changes: 1 addition & 1 deletion src/webargs/falconparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _raw_load_json(self, req):
non-json, even if the request body is parseable as json."""
if not is_json_request(req) or req.content_length in (None, 0):
return core.missing
body = req.stream.read()
body = req.stream.read(req.content_length)
if body:
return core.parse_json(body)
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/test_falconparser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import falcon.testing

from webargs.testing import CommonTestCase
from tests.apps.falcon_app import create_app
Expand Down Expand Up @@ -42,3 +43,10 @@ def test_invalid_json(self, testapp):
def test_parsing_headers(self, testapp):
res = testapp.get("/echo_headers", headers={"name": "Fred"})
assert res.json == {"NAME": "Fred"}

# `falcon.testing.TestClient.simulate_request` parses request with `wsgiref`
def test_body_parsing_works_with_simulate(self):
app = self.create_app()
client = falcon.testing.TestClient(app)
res = client.simulate_post("/echo_json", json={"name": "Fred"},)
assert res.json == {"name": "Fred"}

0 comments on commit 7ccb1ad

Please sign in to comment.