{"version":3,"file":"apply-headers.cjs","sources":["../../../src/router/http/apply-headers.ts"],"sourcesContent":["import type { MatchPCREResult } from '../pcre';\nimport { applyPCREMatches } from '../pcre';\n\n/**\n * Applies a set of headers to a response.\n *\n * If the header key is `set-cookie`, the value will be appended. Otherwise, the value will be set\n * and overridden to prevent duplicates which sometimes happens with headers like `x-matched-path`.\n *\n * @param target Headers object to apply to.\n * @param source Headers to apply.\n * @param pcreMatch PCRE match result to apply to header values.\n */\nexport const applyHeaders = (\n\ttarget: Headers,\n\tsource: Record<string, string> | Headers,\n\tpcreMatch?: MatchPCREResult,\n): void => {\n\tconst entries = source instanceof Headers ? source.entries() : Object.entries(source);\n\tfor (const [key, value] of entries) {\n\t\tconst lowerKey = key.toLowerCase();\n\t\tconst newValue = pcreMatch?.match\n\t\t\t? applyPCREMatches(value, pcreMatch.match, pcreMatch.captureGroupKeys)\n\t\t\t: value;\n\n\t\tif (lowerKey === 'set-cookie') {\n\t\t\ttarget.append(lowerKey, newValue);\n\t\t} else {\n\t\t\ttarget.set(lowerKey, newValue);\n\t\t}\n\t}\n};\n"],"names":["applyHeaders","target","source","pcreMatch","entries","key","value","lowerKey","newValue","applyPCREMatches"],"mappings":"sKAaO,MAAMA,EAAe,CAC3BC,EACAC,EACAC,IACU,CACJ,MAAAC,EAAUF,aAAkB,QAAUA,EAAO,UAAY,OAAO,QAAQA,CAAM,EACpF,SAAW,CAACG,EAAKC,CAAK,IAAKF,EAAS,CAC7B,MAAAG,EAAWF,EAAI,cACfG,EAAWL,GAAA,MAAAA,EAAW,MACzBM,mBAAiBH,EAAOH,EAAU,MAAOA,EAAU,gBAAgB,EACnEG,EAECC,IAAa,aACTN,EAAA,OAAOM,EAAUC,CAAQ,EAEzBP,EAAA,IAAIM,EAAUC,CAAQ,CAE/B,CACD"}