@@ -196,6 +196,29 @@ async def handler(request: web.Request) -> web.Response:
196196 resp .release ()
197197
198198
199+ async def test_content_length_invalid (
200+ aiohttp_client : AiohttpClient ,
201+ ) -> None :
202+ async def handler (request : web .Request ) -> web .Response :
203+ body = await request .read ()
204+ return web .Response (body = body )
205+
206+ app = web .Application ()
207+ app .router .add_post ("/" , handler )
208+ client = await aiohttp_client (app )
209+
210+ resp = await client .post ("/" , data = b"hello world" , headers = {CONTENT_LENGTH : "11" })
211+ assert resp .status == 200
212+ assert await resp .read () == b"hello world"
213+ resp .release ()
214+
215+ with pytest .raises (ValueError , match = "Invalid Content-Length header" ):
216+ await client .post ("/" , data = b"hello world" , headers = {CONTENT_LENGTH : "-100" })
217+
218+ with pytest .raises (ValueError , match = "Invalid Content-Length header" ):
219+ await client .post ("/" , data = b"hello world" , headers = {CONTENT_LENGTH : " 100" })
220+
221+
199222@pytest .mark .skipif (sys .version_info < (3 , 11 ), reason = "Needs Task.cancelling()" )
200223async def test_cancel_shutdown (aiohttp_client : AiohttpClient ) -> None :
201224 async def handler (request : web .Request ) -> web .Response :
0 commit comments