Entirely remove request body queue.

This commit is contained in:
L. Kärkkäinen
2020-02-26 19:23:55 +02:00
parent b87364bd91
commit 29c6f3c49f
4 changed files with 4 additions and 62 deletions

View File

@@ -251,11 +251,7 @@ class ASGIApp:
instance.transport,
sanic_app,
)
instance.request.stream = StreamBuffer(
sanic_app.config.REQUEST_BUFFER_QUEUE_SIZE,
protocol=instance
)
instance.request.stream = StreamBuffer(protocol=instance)
return instance

View File

@@ -47,17 +47,12 @@ class RequestParameters(dict):
class StreamBuffer:
def __init__(self, buffer_size=100, protocol=None):
self._queue = asyncio.Queue(buffer_size)
def __init__(self, protocol=None):
self._protocol = protocol
async def read(self):
""" Stop reading when gets None """
if self._protocol:
return await self._protocol.stream_body()
payload = await self._queue.get()
self._queue.task_done()
return payload
return await self._protocol.stream_body()
async def __aiter__(self):
while True:
@@ -66,16 +61,6 @@ class StreamBuffer:
return
yield data
async def put(self, payload):
await self._queue.put(payload)
def is_full(self):
return self._queue.full()
@property
def buffer_size(self):
return self._queue.maxsize
class Request:
"""Properties of an HTTP request such as URL, headers, etc."""

View File

@@ -266,9 +266,7 @@ class HttpProtocol(asyncio.Protocol):
if headers.get(EXPECT_HEADER):
self._status = Status.EXPECT
self.expect_handler()
self.request.stream = StreamBuffer(
self.request_buffer_queue_size, protocol=self,
)
self.request.stream = StreamBuffer(protocol=self)
if body is True:
self._request_chunked = True
pos -= 2 # One CRLF stays in buffer