/**
* Compares response headers for exploratory work with limited memory usage.
*
* @param {Response} response The Response object to inspect.
* @returns {object} An object containing header comparisons.
*/
function compareHeaders(response) {
const headers = response.headers.getValues(); // Get all headers as an array of arrays.
const headerNames = Object.keys(headers[0]); // Get the header names.
const headerComparisons = {};
for (const headerName of headerNames) {
const values = headers.map(header => header.get(headerName)); // Extract values for each header.
// Check if header has at least two values for comparison.
if (values.length >= 2) {
const uniqueValues = [...new Set(values)]; // Remove duplicate values.
if (uniqueValues.length > 1) {
headerComparisons[headerName] = {
values: uniqueValues, // Store the unique header values.
count: values.length //Store the count of values
};
}
}
}
return headerComparisons;
}
Add your comment