| 232 | return self._receive |
| 233 | |
| 234 | async def stream(self) -> AsyncGenerator[bytes, None]: |
| 235 | if hasattr(self, "_body"): |
| 236 | yield self._body |
| 237 | yield b"" |
| 238 | return |
| 239 | if self._stream_consumed: |
| 240 | raise RuntimeError("Stream consumed") |
| 241 | while not self._stream_consumed: |
| 242 | message = await self._receive() |
| 243 | if message["type"] == "http.request": |
| 244 | body = message.get("body", b"") |
| 245 | if not message.get("more_body", False): |
| 246 | self._stream_consumed = True |
| 247 | if body: |
| 248 | yield body |
| 249 | elif message["type"] == "http.disconnect": # pragma: no branch |
| 250 | self._is_disconnected = True |
| 251 | raise ClientDisconnect() |
| 252 | yield b"" |
| 253 | |
| 254 | async def body(self) -> bytes: |
| 255 | if not hasattr(self, "_body"): |