@@ -51,6 +51,33 @@ async def app(scope: Scope, receive: Receive, send: Send) -> None:
5151 )
5252
5353
54+ @pytest .mark .asyncio
55+ async def test_streaming_request () -> None :
56+ async def app (scope : Scope , receive : Receive , send : Send ) -> None :
57+ request = Request (scope , receive = receive )
58+ body = await request .json ()
59+ text = f"message={ body ['message' ]!r} "
60+
61+ response = PlainTextResponse (text )
62+ await response (scope , receive , send )
63+
64+ app = LLSDMiddleware (app )
65+
66+ async def stream_bytes (content ):
67+ b = llsd .format_xml (content )
68+ for chunk in range (0 , len (b ), 2 ):
69+ yield b [chunk : chunk + 2 ]
70+
71+ async with httpx .AsyncClient (app = app , base_url = "http://testserver" ) as client :
72+ r = await client .post (
73+ "/" ,
74+ content = stream_bytes ({"message" : "Hello, world!" }),
75+ headers = {"content-type" : "application/llsd+xml" },
76+ )
77+ assert r .status_code == 200
78+ assert r .text == "message='Hello, world!'"
79+
80+
5481@pytest .mark .asyncio
5582async def test_non_llsd_request () -> None :
5683 async def app (scope : Scope , receive : Receive , send : Send ) -> None :
0 commit comments