File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -288,3 +288,34 @@ async def mock_receive() -> HTTPDisconnectEvent:
288288 body = b"" .join (received ).decode ()
289289 assert "hello" in body
290290 assert "world" in body
291+
292+
293+ async def test_sse_response_send_body_without_ping () -> None :
294+ """ASGIStreamingSSEResponse.send_body delegates to parent when ping_interval is None."""
295+
296+ async def gen () -> AsyncIterator [bytes ]:
297+ yield b"data: hello\r \n \r \n "
298+
299+ response = ASGIStreamingSSEResponse (
300+ iterator = gen (),
301+ ping_interval = None ,
302+ media_type = "text/event-stream" ,
303+ status_code = 200 ,
304+ )
305+
306+ received : list [bytes ] = []
307+
308+ async def mock_send (message : Message ) -> None :
309+ if message .get ("type" ) == "http.response.body" :
310+ body = message .get ("body" , b"" )
311+ received .append (body if isinstance (body , bytes ) else b"" )
312+
313+ async def mock_receive () -> HTTPDisconnectEvent :
314+ await anyio .sleep (10 )
315+ return {"type" : "http.disconnect" }
316+
317+ await response .send_body (mock_send , mock_receive )
318+
319+ body = b"" .join (received ).decode ()
320+ assert "hello" in body
321+ assert ": ping" not in body
You can’t perform that action at this time.
0 commit comments