Function: toCmcdHeaders()
ts
function toCmcdHeaders(cmcd, options?): Record<CmcdHeaderField, string>;Defined in: toCmcdHeaders.ts:22
Convert a CMCD object to request headers
Parameters
cmcd
The CMCD object to convert.
options?
CmcdEncodeOptions = {}
Options for encoding.
Returns
Record<CmcdHeaderField, string>
The CMCD header shards.
See
CTA-5004-B Header Field Definition
Example
ts
const data = {
br: [1000],
'com.example-hello': 'world',
ec: ['ERR001', 'ERR002'],
su: true,
}
const options = {
version: 2 as const,
reportingMode: CmcdReportingMode.REQUEST,
customHeaderMap: {
[CmcdHeaderField.OBJECT]: ['com.example-hello' as CmcdCustomKey],
},
}
deepEqual(toCmcdHeaders(data, options), {
'CMCD-Object': 'br=(1000),com.example-hello="world"',
'CMCD-Request': 'su',
'CMCD-Session': 'v=2',
'CMCD-Status': 'ec=("ERR001" "ERR002")',
})