Fix slow upload

This commit is contained in:
Channel Cat 2017-01-25 01:19:21 -08:00
parent 0ad31a471b
commit 85a28d3c30

View File

@ -49,7 +49,7 @@ class HttpProtocol(asyncio.Protocol):
# event loop, connection # event loop, connection
'loop', 'transport', 'connections', 'signal', 'loop', 'transport', 'connections', 'signal',
# request params # request params
'parser', 'request', 'url', 'headers', 'parser', 'request', 'url', 'headers', 'body',
# request config # request config
'request_handler', 'request_timeout', 'request_max_size', 'request_handler', 'request_timeout', 'request_max_size',
# connection management # connection management
@ -64,6 +64,7 @@ class HttpProtocol(asyncio.Protocol):
self.parser = None self.parser = None
self.url = None self.url = None
self.headers = None self.headers = None
self.body = []
self.signal = signal self.signal = signal
self.connections = connections self.connections = connections
self.request_handler = request_handler self.request_handler = request_handler
@ -148,12 +149,11 @@ class HttpProtocol(asyncio.Protocol):
) )
def on_body(self, body): def on_body(self, body):
if self.request.body: self.body.append(body)
self.request.body += body
else:
self.request.body = body
def on_message_complete(self): 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_task = self.loop.create_task(
self.request_handler(self.request, self.write_response)) self.request_handler(self.request, self.write_response))
@ -217,6 +217,7 @@ class HttpProtocol(asyncio.Protocol):
self.request = None self.request = None
self.url = None self.url = None
self.headers = None self.headers = None
self.body = []
self._request_handler_task = None self._request_handler_task = None
self._total_request_size = 0 self._total_request_size = 0