()
| 328 | } |
| 329 | |
| 330 | function getCustomHeaders(): Record<string, string> { |
| 331 | const customHeaders: Record<string, string> = {} |
| 332 | const customHeadersEnv = process.env.ANTHROPIC_CUSTOM_HEADERS |
| 333 | |
| 334 | if (!customHeadersEnv) return customHeaders |
| 335 | |
| 336 | // Split by newlines to support multiple headers |
| 337 | const headerStrings = customHeadersEnv.split(/\n|\r\n/) |
| 338 | |
| 339 | for (const headerString of headerStrings) { |
| 340 | if (!headerString.trim()) continue |
| 341 | |
| 342 | // Parse header in format "Name: Value" (curl style). Split on first `:` |
| 343 | // then trim — avoids regex backtracking on malformed long header lines. |
| 344 | const colonIdx = headerString.indexOf(':') |
| 345 | if (colonIdx === -1) continue |
| 346 | const name = headerString.slice(0, colonIdx).trim() |
| 347 | const value = headerString.slice(colonIdx + 1).trim() |
| 348 | if (name) { |
| 349 | customHeaders[name] = value |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | return customHeaders |
| 354 | } |
| 355 | |
| 356 | export const CLIENT_REQUEST_ID_HEADER = 'x-client-request-id' |
| 357 |
no outgoing calls
no test coverage detected