Skip to content

Commit

Permalink
DO NOT MERGE
Browse files Browse the repository at this point in the history
Trying to demonstrate that the test will not even fail when too many bytes are sent.
  • Loading branch information
mdellweg committed Jan 8, 2025
1 parent 0ac82e1 commit e9e0f61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 0 additions & 1 deletion aiohttp/http_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ async def write(
if self.length >= chunk_len:
self.length = self.length - chunk_len
else:
chunk = chunk[: self.length]
self.length = 0
if not chunk:
return
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def _sendfile_fallback(
chunk_size = self._chunk_size
loop = asyncio.get_event_loop()
chunk = await loop.run_in_executor(
None, self._seek_and_read, fobj, offset, min(chunk_size, count)
None, self._seek_and_read, fobj, offset, chunk_size
)
while chunk:
await writer.write(chunk)
Expand Down
14 changes: 11 additions & 3 deletions tests/test_web_sendfile_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,9 +1179,15 @@ async def handler(request: web.Request) -> web.FileResponse:
app.router.add_get("/", handler)
client = await aiohttp_client(app)

resp = await client.get("/", headers={"Range": "bytes=20-40"})
assert resp.status == 206
body = await resp.read()
async with await client.get("/", headers={"Range": "bytes=20-40"}) as resp:
assert resp.status == 206
assert resp.headers["content-length"] == "21"
body = await resp.read()

async with await client.get("/", headers={"Range": "bytes=20-40"}) as resp:
assert resp.status == 206
assert resp.headers["content-length"] == "21"
body2 = await resp.read()

# 21 bytes, because http range headers are including both fenceposts.
assert len(body) == 21
Expand All @@ -1191,3 +1197,5 @@ async def handler(request: web.Request) -> web.FileResponse:
f.seek(20)
content = f.read(21)
assert content == body

assert body == body2

0 comments on commit e9e0f61

Please sign in to comment.