UNPKG

@fgiova/aws-signature

Version:

[![NPM version](https://img.shields.io/npm/v/@fgiova/aws-signature.svg?style=flat)](https://www.npmjs.com/package/@fgiova/aws-signature) ![CI workflow](https://github.com/fgiova/aws-signature/actions/workflows/node.js.yml/badge.svg) [![TypeScript](https:/

35 lines (34 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCanonicalHeaders = getCanonicalHeaders; exports.getCanonicalHeaderList = getCanonicalHeaderList; const constants_1 = require("./constants"); /** * @private */ function getCanonicalHeaders({ headers }, unsignableHeaders, signableHeaders) { const canonical = {}; /* c8 ignore next 3 */ if (!headers) { return canonical; } for (const headerName of Object.keys(headers).sort()) { if (headers[headerName] == undefined) { continue; } const canonicalHeaderName = headerName.toLowerCase(); if (canonicalHeaderName in constants_1.ALWAYS_UNSIGNABLE_HEADERS || unsignableHeaders?.has(canonicalHeaderName) || constants_1.PROXY_HEADER_PATTERN.test(canonicalHeaderName) || constants_1.SEC_HEADER_PATTERN.test(canonicalHeaderName)) { if (!signableHeaders || (signableHeaders && !signableHeaders.has(canonicalHeaderName))) { continue; } } canonical[canonicalHeaderName] = headers[headerName].trim().replace(/\s+/g, " "); } return canonical; } function getCanonicalHeaderList(headers) { return Object.keys(headers).sort().join(";"); }