Skip to content
Draft

test #12400

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,29 @@ async def handler(request: web.Request) -> web.Response:
resp.release()


async def test_content_length_invalid(
aiohttp_client: AiohttpClient,
) -> None:
async def handler(request: web.Request) -> web.Response:
body = await request.read()
return web.Response(body=body)

app = web.Application()
app.router.add_post("/", handler)
client = await aiohttp_client(app)

resp = await client.post("/", data=b"hello world", headers={CONTENT_LENGTH: "11"})
assert resp.status == 200
assert await resp.read() == b"hello world"
resp.release()

with pytest.raises(ValueError, match="Invalid Content-Length header"):
await client.post("/", data=b"hello world", headers={CONTENT_LENGTH: "-100"})

with pytest.raises(ValueError, match="Invalid Content-Length header"):
await client.post("/", data=b"hello world", headers={CONTENT_LENGTH: " 100"})


@pytest.mark.skipif(sys.version_info < (3, 11), reason="Needs Task.cancelling()")
async def test_cancel_shutdown(aiohttp_client: AiohttpClient) -> None:
async def handler(request: web.Request) -> web.Response:
Expand Down
Loading