Read next body chunk asynchronously for streaming. Returns: bytes: Next chunk of body data, or None if body is complete.
(self)
| 299 | return self.request_body.getvalue() |
| 300 | |
| 301 | async def read_body_chunk(self): |
| 302 | """Read next body chunk asynchronously for streaming. |
| 303 | |
| 304 | Returns: |
| 305 | bytes: Next chunk of body data, or None if body is complete. |
| 306 | """ |
| 307 | import asyncio |
| 308 | |
| 309 | # Initialize event lazily (avoids event loop issues at construction) |
| 310 | if self._body_event is None: |
| 311 | self._body_event = asyncio.Event() |
| 312 | # If data already arrived before event existed, set it now |
| 313 | # This prevents race where DATA frames arrive before first read |
| 314 | if self._body_chunks or self._body_complete: |
| 315 | self._body_event.set() |
| 316 | |
| 317 | while True: |
| 318 | # Return chunk if available |
| 319 | if self._body_chunks: |
| 320 | return self._body_chunks.pop(0) |
| 321 | |
| 322 | # No more data expected |
| 323 | if self._body_complete: |
| 324 | return None |
| 325 | |
| 326 | # Wait for more data |
| 327 | self._body_event.clear() |
| 328 | await self._body_event.wait() |
| 329 | |
| 330 | def get_pseudo_headers(self): |
| 331 | """Extract HTTP/2 pseudo-headers from request headers. |