MCPcopy Index your code
hub / github.com/codeaashu/claude-code / detectGateway

Function detectGateway

src/services/api/logging.ts:107–139  ·  view source on GitHub ↗
({
  headers,
  baseUrl,
}: {
  headers?: globalThis.Headers
  baseUrl?: string
})

Source from the content-addressed store, hash-verified

105}
106
107function detectGateway({
108 headers,
109 baseUrl,
110}: {
111 headers?: globalThis.Headers
112 baseUrl?: string
113}): KnownGateway | undefined {
114 if (headers) {
115 // Header names are already lowercase from the Headers API
116 const headerNames: string[] = []
117 headers.forEach((_, key) => headerNames.push(key))
118 for (const [gw, { prefixes }] of Object.entries(GATEWAY_FINGERPRINTS)) {
119 if (prefixes.some(p => headerNames.some(h => h.startsWith(p)))) {
120 return gw as KnownGateway
121 }
122 }
123 }
124
125 if (baseUrl) {
126 try {
127 const host = new URL(baseUrl).hostname.toLowerCase()
128 for (const [gw, suffixes] of Object.entries(GATEWAY_HOST_SUFFIXES)) {
129 if (suffixes.some(s => host.endsWith(s))) {
130 return gw as KnownGateway
131 }
132 }
133 } catch {
134 // malformed URL — ignore
135 }
136 }
137
138 return undefined
139}
140
141function getAnthropicEnvMetadata() {
142 return {

Callers 2

logAPIErrorFunction · 0.85
logAPISuccessAndDurationFunction · 0.85

Calls 3

forEachMethod · 0.80
entriesMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected