1. /**
  2. * Compares response headers for exploratory work with limited memory usage.
  3. *
  4. * @param {Response} response The Response object to inspect.
  5. * @returns {object} An object containing header comparisons.
  6. */
  7. function compareHeaders(response) {
  8. const headers = response.headers.getValues(); // Get all headers as an array of arrays.
  9. const headerNames = Object.keys(headers[0]); // Get the header names.
  10. const headerComparisons = {};
  11. for (const headerName of headerNames) {
  12. const values = headers.map(header => header.get(headerName)); // Extract values for each header.
  13. // Check if header has at least two values for comparison.
  14. if (values.length >= 2) {
  15. const uniqueValues = [...new Set(values)]; // Remove duplicate values.
  16. if (uniqueValues.length > 1) {
  17. headerComparisons[headerName] = {
  18. values: uniqueValues, // Store the unique header values.
  19. count: values.length //Store the count of values
  20. };
  21. }
  22. }
  23. }
  24. return headerComparisons;
  25. }

Add your comment