//#region src/libs/normalize-headers.ts
/**
* Normalize headers:
*
* - Electron modifies the headers to allow CORS, this function hides the modifications
* - Restores original headers
* - Normalizes the header keys
* - Sorts headers alphabetically
* - converts to an object
*
*/
var normalizeHeaders = (_headers, removeProxyHeaders = false) => {
	const headers = Object.fromEntries(_headers);
	if (removeProxyHeaders) [
		"Access-Control-Allow-Credentials",
		"Access-Control-Allow-Headers",
		"Access-Control-Allow-Methods",
		"Access-Control-Allow-Origin",
		"Access-Control-Expose-Headers"
	].map((header) => header.toLowerCase()).forEach((header) => delete headers[header]);
	/** Exact key of the modified headers header */
	const modifiedHeaderKey = Object.keys(headers).find((key) => key.toLowerCase() === "x-scalar-modified-headers");
	/** List of modified headers */
	const modifiedHeaders = modifiedHeaderKey ? headers[modifiedHeaderKey]?.toString().split(", ")?.map((value) => value.toLowerCase()) ?? [] : [];
	Object.keys(headers).forEach((key) => {
		if (modifiedHeaders.includes(key.toLowerCase())) delete headers[key];
	});
	if (modifiedHeaderKey) delete headers[modifiedHeaderKey];
	Object.keys(headers).forEach((key) => {
		const ORIGINAL_KEY_REGEX = /^x-scalar-original-/i;
		if (ORIGINAL_KEY_REGEX.test(key)) {
			const originalKey = key.replace(ORIGINAL_KEY_REGEX, "");
			if (headers[key]) {
				headers[originalKey] = headers[key];
				delete headers[key];
			}
		}
	});
	Object.keys(headers).forEach((key) => {
		const formattedKey = formatHeaderKey(key);
		if (key !== formattedKey && headers[key]) {
			headers[formattedKey] = headers[key];
			delete headers[key];
		}
	});
	return Object.fromEntries(Object.entries(headers).sort(([a], [b]) => a.localeCompare(b)));
};
/** Make the first letter and all letters after a dash uppercase */
var formatHeaderKey = (key) => key.split("-").map((word) => {
	return word.charAt(0).toUpperCase() + word.toLowerCase().slice(1);
}).join("-");
//#endregion
export { formatHeaderKey, normalizeHeaders };

//# sourceMappingURL=normalize-headers.js.map