Browse Source

Work around aiohttp bug on parsing chunked transfer encoding responses when the buffer ends in an unfortunate spot

https://github.com/aio-libs/aiohttp/issues/4630
tags/v0.2.4^0
JustAnotherArchivist 4 years ago
parent
commit
b6003af1e5
1 changed files with 4 additions and 0 deletions
  1. +4
    -0
      qwarc/aiohttp.py

+ 4
- 0
qwarc/aiohttp.py View File

@@ -127,11 +127,15 @@ class ClientResponse(aiohttp.client_reqrep.ClientResponse):
except (KeyError, ValueError, TypeError):
length = None
parser = aiohttp.http_parser.HttpPayloadParser(payload, length = length, chunked = respMsg.chunked, compression = respMsg.compression, code = respMsg.code, method = self.method)
while beginning.endswith(b'0\r\n') or beginning.endswith(b'0\r\n\r'): # https://github.com/aio-libs/aiohttp/issues/4630
beginning = beginning + self._rawData.responseData.read(4)
eof, data = parser.feed_data(beginning[pos + 4:])
while True:
chunk = self._rawData.responseData.read(1048576)
if not chunk:
break
while chunk.endswith(b'0\r\n') or chunk.endswith(b'0\r\n\r'): # https://github.com/aio-libs/aiohttp/issues/4630
chunk = chunk + self._rawData.responseData.read(4)
eof, data = parser.feed_data(chunk)
if nbytes is not None and payload.data.tell() >= nbytes:
if payload.exc:


Loading…
Cancel
Save