| 498 | self.wfile.write(data) |
| 499 | |
| 500 | def _send_file(self, path: Path) -> None: |
| 501 | if not path.exists() or not path.is_file(): |
| 502 | self._send_json({"ok": False, "error": "Not found"}, status=HTTPStatus.NOT_FOUND) |
| 503 | return |
| 504 | data = path.read_bytes() |
| 505 | mime = mimetypes.guess_type(str(path))[0] or "application/octet-stream" |
| 506 | if mime.startswith("text/") or mime in {"application/javascript", "application/json"}: |
| 507 | mime = f"{mime}; charset=utf-8" |
| 508 | self.send_response(200) |
| 509 | self.send_header("Content-Type", mime) |
| 510 | self.send_header("Content-Length", str(len(data))) |
| 511 | self.send_header("Cache-Control", "no-store") |
| 512 | self.end_headers() |
| 513 | self.wfile.write(data) |
| 514 | |
| 515 | def _handle_api(self, routes: Dict[str, ApiHandler], body: Dict[str, Any] | None = None) -> None: |
| 516 | path, query_params = _query(self.path) |