(
self, send: Send, start: int, end: int, file_size: int, send_header_only: bool
)
| 396 | await send({"type": "http.response.body", "body": chunk, "more_body": more_body}) |
| 397 | |
| 398 | async def _handle_single_range( |
| 399 | self, send: Send, start: int, end: int, file_size: int, send_header_only: bool |
| 400 | ) -> None: |
| 401 | headers = MutableHeaders(raw=list(self.raw_headers)) |
| 402 | headers["content-range"] = f"bytes {start}-{end - 1}/{file_size}" |
| 403 | headers["content-length"] = str(end - start) |
| 404 | await send({"type": "http.response.start", "status": 206, "headers": headers.raw}) |
| 405 | if send_header_only: |
| 406 | await send({"type": "http.response.body", "body": b"", "more_body": False}) |
| 407 | else: |
| 408 | async with await anyio.open_file(self.path, mode="rb") as file: |
| 409 | await file.seek(start) |
| 410 | more_body = True |
| 411 | while more_body: |
| 412 | chunk = await file.read(min(self.chunk_size, end - start)) |
| 413 | start += len(chunk) |
| 414 | more_body = len(chunk) == self.chunk_size and start < end |
| 415 | await send({"type": "http.response.body", "body": chunk, "more_body": more_body}) |
| 416 | |
| 417 | async def _handle_multiple_ranges( |
| 418 | self, |
no test coverage detected