From ee27c689e12e1074cbd7ae235f0b0c076130422a Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 23 Mar 2017 20:06:39 +0800 Subject: [PATCH 1/3] commented aiohttp load response body in testing --- sanic/testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sanic/testing.py b/sanic/testing.py index 4fde428c..611f709d 100644 --- a/sanic/testing.py +++ b/sanic/testing.py @@ -22,8 +22,8 @@ class SanicTestClient: cookies=cookies, connector=conn) as session: async with getattr( session, method.lower())(url, *args, **kwargs) as response: - response.text = await response.text() - response.body = await response.read() + # response.text = await response.text() + # response.body = await response.read() return response def _sanic_endpoint_test( From 1562b81522d827539545a28e592aed1966ce0099 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 23 Mar 2017 20:48:57 +0800 Subject: [PATCH 2/3] add arg load_body in testing --- sanic/testing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sanic/testing.py b/sanic/testing.py index 611f709d..d7e73e56 100644 --- a/sanic/testing.py +++ b/sanic/testing.py @@ -20,10 +20,12 @@ class SanicTestClient: conn = aiohttp.TCPConnector(verify_ssl=False) async with aiohttp.ClientSession( cookies=cookies, connector=conn) as session: + load_body = 'load_body' not in kwargs or kwargs.pop('load_body') async with getattr( session, method.lower())(url, *args, **kwargs) as response: - # response.text = await response.text() - # response.body = await response.read() + if load_body: + response.text = await response.text() + response.body = await response.read() return response def _sanic_endpoint_test( From 09885534c686d490733f9cc6c59f4a66859bc32d Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 10 Apr 2017 18:31:28 +0800 Subject: [PATCH 3/3] fixed #615 --- sanic/response.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/response.py b/sanic/response.py index 4eecaf79..bebb8071 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -129,7 +129,7 @@ class StreamingHTTPResponse(BaseHTTPResponse): data = self._encode_body(data) self.transport.write( - b"%b\r\n%b\r\n" % (str(len(data)).encode(), data)) + b"%x\r\n%b\r\n" % (len(data), data)) async def stream( self, version="1.1", keep_alive=False, keep_alive_timeout=None):