Skip to content

Commit 7ccb1ad

Browse files
authored
Merge pull request #477 from suola/falcon-parser-wsgi-ref-read-requires-argument
stdlib `wsgiref` requires argument for `read()`
2 parents 2f8b0d2 + 9b86165 commit 7ccb1ad

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ Contributors (chronological)
4646
* `@dodumosu <https://github.com/dodumosu>`_
4747
* Nate Dellinger `@Nateyo <https://github.com/Nateyo>`_
4848
* Karthikeyan Singaravelan `@tirkarthi <https://github.com/tirkarthi>`_
49+
* Sami Salonen `@suola <https://github.com/suola>`_

src/webargs/falconparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _raw_load_json(self, req):
103103
non-json, even if the request body is parseable as json."""
104104
if not is_json_request(req) or req.content_length in (None, 0):
105105
return core.missing
106-
body = req.stream.read()
106+
body = req.stream.read(req.content_length)
107107
if body:
108108
return core.parse_json(body)
109109
else:

tests/test_falconparser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import falcon.testing
23

34
from webargs.testing import CommonTestCase
45
from tests.apps.falcon_app import create_app
@@ -42,3 +43,10 @@ def test_invalid_json(self, testapp):
4243
def test_parsing_headers(self, testapp):
4344
res = testapp.get("/echo_headers", headers={"name": "Fred"})
4445
assert res.json == {"NAME": "Fred"}
46+
47+
# `falcon.testing.TestClient.simulate_request` parses request with `wsgiref`
48+
def test_body_parsing_works_with_simulate(self):
49+
app = self.create_app()
50+
client = falcon.testing.TestClient(app)
51+
res = client.simulate_post("/echo_json", json={"name": "Fred"},)
52+
assert res.json == {"name": "Fred"}

0 commit comments

Comments
 (0)