Skip to content

Commit ca17e81

Browse files
author
cndaqianng
committed
长上下文代理.pages主页
1 parent daf6d04 commit ca17e81

File tree

4 files changed

+507
-3
lines changed

4 files changed

+507
-3
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
[简体中文](README_zh.md)
44

5-
Claude Code Proxy — lightweight, direct reverse proxy to switch providers without restarting Claude.
5+
Claude Code Proxy is a lightweight reverse proxy tool designed for Claude Code users. Switch between multiple Claude API providers via Web UI, with automatic model list fetching, JSON config hot-reload, without restarting Claude Code.
6+
7+
**Use cases:** Manage multiple public/forwarding API keys, test endpoint stability, centralize Claude API access management.
68

79
![demo](demo.png)
810

README_zh.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Claude Code Proxy
22

3-
Claude Code Proxy — 轻量直连反向代理,无需重启即可切换供应商。
3+
Claude Code Proxy 是一个轻量级反向代理工具,专为 Claude Code 用户设计。通过 Web UI 在多个 Claude API 供应商之间快速切换,支持自动拉取模型列表,JSON 配置热重载,无需重启 Claude Code。
4+
5+
**适用场景:** 管理多个公益站/转发站 API 密钥,测试不同端点的稳定性,统一管理多个 Claude API 访问点。
46

57

68
## 快速开始

ccproxy.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,30 @@ def _send_text(self, body: bytes, content_type: str) -> None:
252252
self.wfile.write(body)
253253

254254
def _read_body(self) -> bytes:
255+
transfer_encoding = self.headers.get("Transfer-Encoding", "")
256+
if "chunked" in transfer_encoding.lower():
257+
chunks: List[bytes] = []
258+
while True:
259+
line = self.rfile.readline()
260+
if not line:
261+
break
262+
size_str = line.split(b";", 1)[0].strip()
263+
try:
264+
size = int(size_str, 16)
265+
except ValueError:
266+
break
267+
if size == 0:
268+
# Drain trailing headers after last chunk.
269+
while True:
270+
tail = self.rfile.readline()
271+
if not tail or tail in (b"\r\n", b"\n"):
272+
break
273+
break
274+
data = self.rfile.read(size)
275+
chunks.append(data)
276+
# Consume the trailing CRLF after each chunk.
277+
self.rfile.read(2)
278+
return b"".join(chunks)
255279
length = int(self.headers.get("Content-Length", "0"))
256280
return self.rfile.read(length) if length > 0 else b""
257281

@@ -411,7 +435,7 @@ def _proxy_messages(self) -> None:
411435
header_name = override.get("token_header") or provider.get("token_header", "Authorization")
412436
header_format = override.get("token_header_format") or provider.get("token_header_format", "Bearer {token}")
413437
headers[header_name] = header_format.format(token=token)
414-
timeout = state.get_timeout()
438+
timeout = (10.0, state.get_timeout())
415439

416440
try:
417441
resp = requests.post(

0 commit comments

Comments
 (0)