File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1193,6 +1193,34 @@ async def handler(request: web.Request) -> web.StreamResponse:
11931193 resp .release ()
11941194
11951195
1196+ async def test_stream_response_empty_write_between_chunks (
1197+ aiohttp_client : AiohttpClient ,
1198+ ) -> None :
1199+ """Test that empty writes between real chunks are harmless.
1200+
1201+ Simulates a streaming handler that writes empty bytes between data,
1202+ as can happen when piping from a source that produces empty reads.
1203+ """
1204+
1205+ async def handler (request : web .Request ) -> web .StreamResponse :
1206+ resp = web .StreamResponse ()
1207+ resp .enable_chunked_encoding ()
1208+ await resp .prepare (request )
1209+ await resp .write (b"hello" )
1210+ await resp .write (b"" )
1211+ await resp .write (b"world" )
1212+ return resp
1213+
1214+ app = web .Application ()
1215+ app .router .add_get ("/" , handler )
1216+ client = await aiohttp_client (app )
1217+
1218+ resp = await client .get ("/" )
1219+ assert resp .status == 200
1220+ data = await resp .read ()
1221+ assert data == b"helloworld"
1222+
1223+
11961224async def test_start_without_routes (aiohttp_client : AiohttpClient ) -> None :
11971225 app = web .Application ()
11981226 client = await aiohttp_client (app )
You can’t perform that action at this time.
0 commit comments