Skip to content

Commit

Permalink
Fix FileResponse fallback code
Browse files Browse the repository at this point in the history
In case the FileResponse is using _sendfile_fallback and the requested
range is smaller then the chunk size, we need to only read and send
count bytes.
  • Loading branch information
mdellweg committed Apr 29, 2022
1 parent 0215cdd commit b325660
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/tba.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug in ``FileResponses`` fallback code when the requested range is smaller than the chunk size.
2 changes: 1 addition & 1 deletion aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def _sendfile_fallback(

await loop.run_in_executor(None, fobj.seek, offset)

chunk = await loop.run_in_executor(None, fobj.read, chunk_size)
chunk = await loop.run_in_executor(None, fobj.read, min(chunk_size, count))
while chunk:
await writer.write(chunk)
count = count - chunk_size
Expand Down

0 comments on commit b325660

Please sign in to comment.