Skip to content

Commit 83d3661

Browse files
authored
Do not attempt to jsonify response data (#27)
it's up to a user to turn his response to the string
1 parent f7e4614 commit 83d3661

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

fdk/response.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ def __init__(self, response_data=None, headers=None, status_code=200):
2626
"""
2727
JSON response object
2828
:param response_data: JSON response data (dict, str)
29-
:type response_data: object
29+
:type response_data: str
3030
:param headers: JSON response HTTP headers
3131
:type headers: fdk.headers.GoLikeHeaders
3232
:param status_code: JSON response HTTP status code
3333
:type status_code: int
3434
"""
3535
self.status_code = status_code
36-
self.response_data = ujson.dumps(response_data)
36+
self.response_data = response_data if response_data else ""
3737
self.headers = hrs.GoLikeHeaders({})
3838
if isinstance(headers, dict):
3939
self.headers = hrs.GoLikeHeaders(headers)
@@ -79,7 +79,7 @@ def __init__(self, context, response_data=None,
7979
:param context: request context
8080
:type context: fdk.context.RequestContext
8181
:param response_data: response data
82-
:type response_data: object
82+
:type response_data: str
8383
:param headers: response headers
8484
:param status_code: status code
8585
:type status_code: int

fdk/tests/test_json.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ async def coroutine_func(ctx, data=None, loop=None):
4242
return "OK"
4343

4444

45+
def none_func(ctx, data=None, loop=None):
46+
return
47+
48+
4549
class TestJSONRequestParser(testtools.TestCase):
4650

4751
def setUp(self):
@@ -96,3 +100,10 @@ def test_corotuine_func_multiple(self):
96100
self.assertIsNotNone(r)
97101
self.assertEqual(200, r.status())
98102
self.assertIn("OK", r.body())
103+
104+
def test_none_func(self):
105+
in_bytes = data.raw_request_without_body.encode('utf8')
106+
r = runner.handle_request(none_func, in_bytes)
107+
self.assertIsNotNone(r)
108+
self.assertEqual(200, r.status())
109+
self.assertIn("", r.body())

0 commit comments

Comments
 (0)