Skip to content

Commit e8498e6

Browse files
Fix issue #784
1 parent f799f2c commit e8498e6

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

hug/interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ def gather_parameters(self, request, response, context, api_version=None, **inpu
604604
input_parameters.update(request.params)
605605

606606
if self.parse_body and request.content_length:
607-
body = request.stream
607+
body = request.bounded_stream
608608
content_type, content_params = parse_content_type(request.content_type)
609609
body_formatter = body and self.inputs.get(content_type, self.api.http.input_format(content_type))
610610
if body_formatter:

tests/test_full_request.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""tests/test_full_request.py.
2+
3+
Test cases that rely on a command being ran against a running hug server
4+
5+
Copyright (C) 2016 Timothy Edmund Crosley
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
10+
to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all copies or
13+
substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
16+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
18+
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19+
OTHER DEALINGS IN THE SOFTWARE.
20+
21+
"""
22+
import time
23+
from subprocess import Popen
24+
25+
import requests
26+
27+
import hug
28+
29+
TEST_HUG_API = """
30+
import hug
31+
32+
33+
@hug.post("/test", output=hug.output_format.json)
34+
def post(body, response):
35+
print(body)
36+
return {'message': 'ok'}
37+
"""
38+
39+
40+
def test_hug_post(tmp_path):
41+
hug_test_file = (tmp_path / "hug_postable.py")
42+
hug_test_file.write_text(TEST_HUG_API)
43+
hug_server = Popen(['hug', '-f', hug_test_file])
44+
time.sleep(1)
45+
requests.post('http://localhost:8000/test', {'data': 'here'})
46+
hug_server.kill()

0 commit comments

Comments
 (0)