Skip to main content

getFlattenedHeadersMap

@h4ad/serverless-adapter > getFlattenedHeadersMap

(function) getFlattenedHeadersMap

Transform a header map and make sure the value is not an array

Signature:

export declare function getFlattenedHeadersMap(headersMap: BothValueHeaders, separator?: string, lowerCaseKey?: boolean): Record<string, string>;

Parameters

ParameterTypeDescription
headersMapBothValueHeadersThe initial headers
separatorstring(Optional) The separator used when we join the array of header's value
lowerCaseKeyboolean(Optional) Should put all keys in lowercase

Returns:

Record<string, string>

Example

const headers = \{ 'accept-encoding': 'gzip', 'accept-language': ['en-US', 'en;q=0.9'] };
const flattenedHeaders = getFlattenedHeadersMap(headers, ',', true);
console.log(flattenedHeaders);
// \{ 'accept-encoding': 'gzip', 'accept-language': 'en-US,en;q=0.9' }