Skip to content

Commit

Permalink
fix first chunk substring search
Browse files Browse the repository at this point in the history
  • Loading branch information
tumb1er committed Jan 31, 2016
1 parent 960b148 commit 3010579
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions aiohttp/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,18 @@ def _read_chunk_from_stream(self, size):
"""
assert size >= len(self._boundary) + 2, \
'Chunk size must be greater or equal than boundary length + 2'
if self._prev_chunk is None:
first_chunk = self._prev_chunk is None
if first_chunk:
self._prev_chunk = yield from self._content.read(size)

chunk = yield from self._content.read(size)

window = self._prev_chunk + chunk
sub = b'\r\n' + self._boundary
idx = window.find(sub, len(self._prev_chunk) - len(sub))
if first_chunk:
idx = window.find(sub)
else:
idx = window.find(sub, len(self._prev_chunk) - len(sub))
if idx >= 0:
# pushing boundary back to content
self._content.unread_data(window[idx:])
Expand Down

0 comments on commit 3010579

Please sign in to comment.