Skip to content

Commit f265783

Browse files
committed
fix(server): omit Authorization header on peer-proxy when caller provides no key
`_proxy_to_peer` set `"Authorization": ""` when `api_key` was empty — a blank-value header, not a missing one. Many HTTP proxies and uvicorn front-ends (nginx, traefik) reject `Authorization: ""` with 400 Bad Request, breaking peer routing for anonymous requests to public hubs. Fix: build the headers dict without the Authorization key and add it only when `api_key` is non-empty, matching the correct "omit, don't blank" contract for optional bearer tokens.
1 parent 5eb5982 commit f265783

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

zhub/server.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,11 +1220,12 @@ async def _proxy_to_peer(peer_url: str, ai_name: str, body: dict[str, Any],
12201220

12211221
target = peer_url.rstrip("/") + f"/{ai_name}/v1/chat/completions"
12221222
chain_str = ",".join(forwarded_by_chain)
1223-
headers = {
1224-
"Authorization": f"Bearer {api_key}" if api_key else "",
1223+
headers: dict[str, str] = {
12251224
"X-Zhub-Forwarded-By": chain_str,
12261225
"Content-Type": "application/json",
12271226
}
1227+
if api_key:
1228+
headers["Authorization"] = f"Bearer {api_key}"
12281229
# Phase 17.0: sign the chain so the receiving hub can verify the
12291230
# request really originated where it claims. Best-effort —
12301231
# silently skipped if crypto isn't installed (recipient sees no

0 commit comments

Comments
 (0)