1. function flagHeaderAnomalies(headers, expectedHeaders) {
  2. const anomalies = [];
  3. for (const headerName in headers) {
  4. if (headers.hasOwnProperty(headerName)) {
  5. const headerValue = headers[headerName];
  6. // Check if header exists in expected headers
  7. if (!expectedHeaders.hasOwnProperty(headerName)) {
  8. anomalies.push({
  9. header: headerName,
  10. value: headerValue,
  11. message: "Header not found in expected headers",
  12. });
  13. continue; // Skip to next header
  14. }
  15. const expectedValue = expectedHeaders[headerName];
  16. // Simple value comparison (can be extended for more complex checks)
  17. if (headerValue !== expectedValue) {
  18. anomalies.push({
  19. header: headerName,
  20. value: headerValue,
  21. expected: expectedValue,
  22. message: "Header value mismatch",
  23. });
  24. }
  25. }
  26. }
  27. return anomalies;
  28. }
  29. // Example usage:
  30. // const actualHeaders = {
  31. // "Content-Type": "application/json",
  32. // "X-Custom-Header": "someValue",
  33. // "Authorization": "Bearer abcdef12345"
  34. // };
  35. // const expectedHeaders = {
  36. // "Content-Type": "application/json",
  37. // "Authorization": "Bearer abcdef12345"
  38. // };
  39. // const anomalies = flagHeaderAnomalies(actualHeaders, expectedHeaders);
  40. // console.log(anomalies);

Add your comment