Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(proxy): allow HEAD method on catch-all passthrough route (#2035)

GUOHAO LIUc41cf444c74a
diff --git a/headroom/providers/proxy_routes.py b/headroom/providers/proxy_routes.py
index b6bd641c3..ddd3795ea 100644
--- a/headroom/providers/proxy_routes.py
+++ b/headroom/providers/proxy_routes.py
@@ -1032,7 +1032,7 @@ def register_provider_routes(app: FastAPI, proxy: Any) -> None:
"gemini",
)
- @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE"])
+ @app.api_route("/{path:path}", methods=["GET", "POST", "PUT", "DELETE", "HEAD"])
async def passthrough(request: Request, path: str):
custom_base = request.headers.get("x-headroom-base-url")
if custom_base:
diff --git a/tests/test_proxy_passthrough_integration.py b/tests/test_proxy_passthrough_integration.py
index 1f86b0090..9e893266d 100644
--- a/tests/test_proxy_passthrough_integration.py
+++ b/tests/test_proxy_passthrough_integration.py
@@ -492,3 +492,36 @@ class TestPassthroughErrorHandling:
content=b"not valid json",
)
assert response.status_code >= 400
+
+
+# =============================================================================
+# HEAD request regression test — GH #2032
+# =============================================================================
+
+
+def test_head_root_returns_200_not_405(monkeypatch: pytest.MonkeyPatch) -> None:
+ """HEAD / must not return 405; Claude Code uses it as connectivity preflight."""
+ from headroom.proxy.server import ProxyConfig, create_app
+
+ # Dummy upstream so the proxy doesn't crash on missing HTTP client.
+ monkeypatch.setenv("ANTHROPIC_TARGET_API_URL", "https://api.anthropic.example")
+
+ config = ProxyConfig(
+ optimize=False,
+ cache_enabled=False,
+ rate_limit_enabled=False,
+ cost_tracking_enabled=False,
+ log_requests=False,
+ ccr_inject_tool=False,
+ ccr_handle_responses=False,
+ ccr_context_tracking=False,
+ image_optimize=False,
+ )
+ app = create_app(config)
+ with TestClient(app) as client:
+ resp = client.head("/")
+ # The upstream is fake (connection error → 502), but the proxy must
+ # *accept* HEAD — a 405 would mean the route is missing.
+ assert resp.status_code != 405, (
+ f"HEAD / returned 405; allowed methods: {resp.headers.get('allow', 'N/A')}"
+ )