| 100 | self.wfile.write(body) |
| 101 | |
| 102 | def _route(self) -> None: |
| 103 | path = self.path.split("?", 1)[0].lower() |
| 104 | length = int(self.headers.get("content-length") or 0) |
| 105 | if length: |
| 106 | self.rfile.read(length) |
| 107 | if path.endswith("/models"): |
| 108 | self._send( |
| 109 | 200, |
| 110 | "application/json", |
| 111 | json.dumps( |
| 112 | model_catalog(supported_endpoints=["/responses", "ws:/responses"]) |
| 113 | ).encode("utf-8"), |
| 114 | ) |
| 115 | return |
| 116 | if path.endswith("/models/session"): |
| 117 | self._send(200, "application/json", b"{}") |
| 118 | return |
| 119 | if "/policy" in path: |
| 120 | self._send( |
| 121 | 200, |
| 122 | "application/json", |
| 123 | json.dumps({"state": "enabled"}).encode("utf-8"), |
| 124 | ) |
| 125 | return |
| 126 | if path.endswith("/responses"): |
| 127 | self._send(200, "text/event-stream", _sse_body(HTTP_TEXT, "resp_stub_http")) |
| 128 | return |
| 129 | self._send( |
| 130 | 404, |
| 131 | "application/json", |
| 132 | json.dumps({"error": "not_found", "path": path}).encode("utf-8"), |
| 133 | ) |
| 134 | |
| 135 | def do_GET(self): # noqa: N802 |
| 136 | self._route() |