| 320 | |
| 321 | # Create a wrapper class that provides write_stream method |
| 322 | class ChunkCapture: |
| 323 | async def write_stream(self, data, end_response=False): |
| 324 | # Convert data to string |
| 325 | if isinstance(data, dict): |
| 326 | chunk = json.dumps(data) |
| 327 | elif isinstance(data, bytes): |
| 328 | chunk = data.decode('utf-8') |
| 329 | else: |
| 330 | chunk = str(data) |
| 331 | response_content.append(chunk) |
| 332 | |
| 333 | capture_chunk = ChunkCapture() |
| 334 |