From 85a28d3c3027a1cf85cb3b9040788d91c3a21ff5 Mon Sep 17 00:00:00 2001 From: Channel Cat Date: Wed, 25 Jan 2017 01:19:21 -0800 Subject: [PATCH 1/2] Fix slow upload --- sanic/server.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index a984854e..00711e91 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -49,7 +49,7 @@ class HttpProtocol(asyncio.Protocol): # event loop, connection 'loop', 'transport', 'connections', 'signal', # request params - 'parser', 'request', 'url', 'headers', + 'parser', 'request', 'url', 'headers', 'body', # request config 'request_handler', 'request_timeout', 'request_max_size', # connection management @@ -64,6 +64,7 @@ class HttpProtocol(asyncio.Protocol): self.parser = None self.url = None self.headers = None + self.body = [] self.signal = signal self.connections = connections self.request_handler = request_handler @@ -148,12 +149,11 @@ class HttpProtocol(asyncio.Protocol): ) def on_body(self, body): - if self.request.body: - self.request.body += body - else: - self.request.body = body + self.body.append(body) def on_message_complete(self): + if self.body: + self.request.body = b''.join(self.body) self._request_handler_task = self.loop.create_task( self.request_handler(self.request, self.write_response)) @@ -217,6 +217,7 @@ class HttpProtocol(asyncio.Protocol): self.request = None self.url = None self.headers = None + self.body = [] self._request_handler_task = None self._total_request_size = 0 From fd118a41fd871bb621ee33f409f8b8511eeb3bb3 Mon Sep 17 00:00:00 2001 From: Channel Cat Date: Wed, 25 Jan 2017 21:56:49 -0800 Subject: [PATCH 2/2] Only use request.body --- sanic/request.py | 2 +- sanic/server.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index 6f02d09b..8fd2c0e9 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -54,7 +54,7 @@ class Request(dict): self.query_string = url_parsed.query.decode('utf-8') # Init but do not inhale - self.body = None + self.body = [] self.parsed_json = None self.parsed_form = None self.parsed_files = None diff --git a/sanic/server.py b/sanic/server.py index 00711e91..d34c6db2 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -49,7 +49,7 @@ class HttpProtocol(asyncio.Protocol): # event loop, connection 'loop', 'transport', 'connections', 'signal', # request params - 'parser', 'request', 'url', 'headers', 'body', + 'parser', 'request', 'url', 'headers', # request config 'request_handler', 'request_timeout', 'request_max_size', # connection management @@ -64,7 +64,6 @@ class HttpProtocol(asyncio.Protocol): self.parser = None self.url = None self.headers = None - self.body = [] self.signal = signal self.connections = connections self.request_handler = request_handler @@ -149,11 +148,11 @@ class HttpProtocol(asyncio.Protocol): ) def on_body(self, body): - self.body.append(body) + self.request.body.append(body) def on_message_complete(self): - if self.body: - self.request.body = b''.join(self.body) + if self.request.body: + self.request.body = b''.join(self.request.body) self._request_handler_task = self.loop.create_task( self.request_handler(self.request, self.write_response)) @@ -217,7 +216,6 @@ class HttpProtocol(asyncio.Protocol): self.request = None self.url = None self.headers = None - self.body = [] self._request_handler_task = None self._total_request_size = 0