Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
/**
* Headers a reverse proxy or tunnel adds when it relays a request. A request that carries any of
* them did not come from a local operator: a same-host proxy connects from loopback, so these
* headers are the only thing that tells the callers behind it apart from the host itself.
*
* Callers can also send these headers themselves. That is safe here because the verdict only ever
* goes one way: their presence downgrades a loopback or private-network peer to "remote", it never
* grants anything.
*
* Pure and dependency-free so the WebSocket sidecar can use it without the auth graph. Keep it in
* step with `hasProxyHopHeader` in scripts/dev/peer-stamp.mjs (a test compares them).
*/
export function hasProxyHopHeader(headers: Record<string, string | string[] | undefined>): boolean {
for (const [rawName, value] of Object.entries(headers)) {
if (!value || (Array.isArray(value) && value.length === 0)) continue;
const name = rawName.toLowerCase();
if (
name.startsWith("x-forwarded-") ||
name === "x-real-ip" ||
name === "forwarded" ||
name === "via"
) {
return true;
}
}
return false;
}