UNPKG

@azure/app-configuration

Version:
74 lines (73 loc) 2.63 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var queryParamPolicy_exports = {}; __export(queryParamPolicy_exports, { queryParamPolicy: () => queryParamPolicy }); module.exports = __toCommonJS(queryParamPolicy_exports); var import_logger = require("../logger.js"); function queryParamPolicy() { return { name: "queryParamPolicy", async sendRequest(request, next) { const originalUrl = request.url; let url; try { url = new URL(originalUrl); } catch (error) { if (error instanceof TypeError) { import_logger.logger.warning(`"[queryParamPolicy] Could not parse URL: ${request.url}"`); return next(request); } throw error; } if (url.search === "") { return next(request); } const params = []; for (const entry of url.search.substring(1).split("&")) { if (entry === "") { continue; } const equalIndex = entry.indexOf("="); const name = equalIndex === -1 ? entry : entry.substring(0, equalIndex); const value = equalIndex === -1 ? "" : entry.substring(equalIndex + 1); params.push({ lowercaseName: name.toLowerCase(), value }); } params.sort((a, b) => { if (a.lowercaseName < b.lowercaseName) { return -1; } else if (a.lowercaseName > b.lowercaseName) { return 1; } return 0; }); const newSearchParams = params.map(({ lowercaseName, value }) => `${lowercaseName}=${value}`).join("&"); const newUrl = url.origin + url.pathname + "?" + newSearchParams + url.hash; if (newUrl !== originalUrl) { request.url = newUrl; } return next(request); } }; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { queryParamPolicy }); //# sourceMappingURL=queryParamPolicy.js.map