()
| 351 | } |
| 352 | |
| 353 | function getCustomHeaders(): Record<string, string> { |
| 354 | const customHeaders: Record<string, string> = {} |
| 355 | const customHeadersEnv = process.env.ANTHROPIC_CUSTOM_HEADERS |
| 356 | |
| 357 | if (!customHeadersEnv) return customHeaders |
| 358 | |
| 359 | // Split by newlines to support multiple headers |
| 360 | const headerStrings = customHeadersEnv.split(/\n|\r\n/) |
| 361 | |
| 362 | for (const headerString of headerStrings) { |
| 363 | if (!headerString.trim()) continue |
| 364 | |
| 365 | // Parse header in format "Name: Value" (curl style). Split on first `:` |
| 366 | // then trim — avoids regex backtracking on malformed long header lines. |
| 367 | const colonIdx = headerString.indexOf(':') |
| 368 | if (colonIdx === -1) continue |
| 369 | const name = headerString.slice(0, colonIdx).trim() |
| 370 | const value = headerString.slice(colonIdx + 1).trim() |
| 371 | if (name) { |
| 372 | customHeaders[name] = value |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | return customHeaders |
| 377 | } |
| 378 | |
| 379 | export const CLIENT_REQUEST_ID_HEADER = 'x-client-request-id' |
| 380 |
no outgoing calls
no test coverage detected