Skip to content

Commit

Permalink
Remove unnessessary pop from http client bytes parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
maximdanilchenko committed Nov 8, 2023
1 parent 2a78ea9 commit f3721df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions aiochclient/http_clients/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ async def post_return_lines(
buffer: bytes = b''
async for chunk in resp.content.iter_any():
lines: List[bytes] = chunk.split(self.line_separator)
lines[0] = buffer + lines[0]
buffer = lines.pop(-1)
for line in lines:
if buffer:
lines[0] = buffer + lines[0]
for line in lines[:-1]:
yield line + self.line_separator
buffer = lines[-1]
assert not buffer

async def post_no_return(
Expand Down
7 changes: 4 additions & 3 deletions aiochclient/http_clients/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ async def post_return_lines(
buffer: bytes = b''
async for chunk in resp.aiter_bytes():
lines: List[bytes] = chunk.split(self.line_separator)
lines[0] = buffer + lines[0]
buffer = lines.pop(-1)
for line in lines:
if buffer:
lines[0] = buffer + lines[0]
for line in lines[:-1]:
yield line + self.line_separator
buffer = lines[-1]
assert not buffer

async def post_no_return(
Expand Down

0 comments on commit f3721df

Please sign in to comment.