@sap-cloud-sdk/http-client
Version:
SAP Cloud SDK for JavaScript http-client
56 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.origins = exports.defaultDisallowedKeys = void 0;
exports.filterCustomRequestConfig = filterCustomRequestConfig;
exports.mergeOptionsWithPriority = mergeOptionsWithPriority;
const util_1 = require("@sap-cloud-sdk/util");
const logger = (0, util_1.createLogger)({
package: 'http-client',
messageContext: 'http-request-config'
});
/**
* Filter disallowed keys from a given custom request config object.
* @param customRequestConfig - a given custom request config object to be filtered
* @param disallowedKeys - A list of keys that are not allowed to be customized.
* @returns Filtered custom request config object.
* @internal
*/
function filterCustomRequestConfig(customRequestConfig, disallowedKeys = exports.defaultDisallowedKeys) {
const removedKeys = Object.keys(customRequestConfig).filter(key => disallowedKeys.includes(key));
if (removedKeys.length) {
logger.warn(`The following keys are found in the custom request config that will be removed: ${removedKeys.join(', ')}`);
}
return (0, util_1.exclude)(disallowedKeys, customRequestConfig);
}
/**
* A list of request config keys that are not allowed to be customized by default.
*/
exports.defaultDisallowedKeys = [
'url',
'baseURL',
'data',
'headers',
'params'
];
/**
* Merge options from a given {@link OriginOptions}. When reaching conflicts, values with higher priorities are chosen.
* @param headersOrParams - Given options with origin information.
* @returns The resulting merged options.
* @internal
*/
function mergeOptionsWithPriority(headersOrParams) {
if (headersOrParams) {
return exports.origins.reduce((mergedHeadersOrParams, origin) => (0, util_1.mergeIgnoreCase)(mergedHeadersOrParams, headersOrParams[origin]), {});
}
}
/**
* @internal
* All origins ordered from low to high priority.
*/
exports.origins = [
'requestConfig',
'destination',
'destinationProperty',
'custom'
];
//# sourceMappingURL=http-request-config.js.map