Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

756 B
Raw Blame
import type { IncomingHttpHeaders } from 'http';

/**
 * Picks the X-Forwarded headers safe to log. The forwarded-for chain holds client addresses, so only
 * its hop count is reported.
 */
export function getForwardedHeaders(headers: IncomingHttpHeaders): Record<string, string | number> {
  const forwarded: Record<string, string | number> = {};
  const forwardedFor = headers['x-forwarded-for'];
  if (forwardedFor) {
    forwarded['x-forwarded-for-hops'] = String(forwardedFor).split(',').length;
  }
  const host = headers['x-forwarded-host'];
  if (host) {
    forwarded['x-forwarded-host'] = String(host);
  }
  const proto = headers['x-forwarded-proto'];
  if (proto) {
    forwarded['x-forwarded-proto'] = String(proto);
  }
  return forwarded;
}