(self)
| 756 | self.wfile.flush() |
| 757 | |
| 758 | def _auth_ok(self): |
| 759 | if not AUTH_SECRET: |
| 760 | return True |
| 761 | prefix = "/" + AUTH_SECRET |
| 762 | if self.path == prefix or self.path.startswith(prefix + "/"): |
| 763 | self.path = self.path[len(prefix):] or "/" |
| 764 | return True |
| 765 | # 鉴权失败时请求体(POST)尚未读取,若保持长连接,服务端下一轮会从残留 |
| 766 | # body 中间开始解析下一个请求,产出的畸形 400 错误页会把残留字节和下一条 |
| 767 | # 请求行拼在一起回显给客户端,可能带出路径里的 secret。这里主动关连接 |
| 768 | # 阻断该复用路径;_send_json 会据 close_connection 追加 Connection: close。 |
| 769 | self.close_connection = True |
| 770 | self._send_json(403, {"type": "error", "error": { |
| 771 | "type": "permission_error", "message": "forbidden"}}) |
| 772 | return False |
| 773 | |
| 774 | def do_GET(self): |
| 775 | if not self._auth_ok(): |
no test coverage detected