MCPcopy Create free account
hub / github.com/tiann/hapi / parseExtraHeaders

Function parseExtraHeaders

cli/src/configuration.ts:14–40  ·  view source on GitHub ↗
(raw: string | undefined, warn: (message: string) => void = console.warn)

Source from the content-addressed store, hash-verified

12import { getCliArgs } from '@/utils/cliArgs'
13
14export function parseExtraHeaders(raw: string | undefined, warn: (message: string) => void = console.warn): Record<string, string> {
15 if (!raw) {
16 return {}
17 }
18
19 try {
20 const parsed = JSON.parse(raw) as unknown
21 if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
22 warn('[WARN] HAPI_EXTRA_HEADERS_JSON must be a JSON object. Ignoring value.')
23 return {}
24 }
25
26 const entries = Object.entries(parsed)
27 const headers = Object.fromEntries(
28 entries.filter((entry): entry is [string, string] => typeof entry[0] === 'string' && typeof entry[1] === 'string')
29 )
30
31 if (Object.keys(headers).length !== entries.length) {
32 warn('[WARN] HAPI_EXTRA_HEADERS_JSON only supports string header values. Ignoring non-string entries.')
33 }
34
35 return headers
36 } catch {
37 warn('[WARN] Failed to parse HAPI_EXTRA_HEADERS_JSON. Ignoring value.')
38 return {}
39 }
40}
41
42class Configuration {
43 private _apiUrl: string

Callers 2

constructorMethod · 0.85

Calls 1

warnFunction · 0.50

Tested by

no test coverage detected