function flagHeaderAnomalies(headers, expectedHeaders) {
const anomalies = [];
for (const headerName in headers) {
if (headers.hasOwnProperty(headerName)) {
const headerValue = headers[headerName];
// Check if header exists in expected headers
if (!expectedHeaders.hasOwnProperty(headerName)) {
anomalies.push({
header: headerName,
value: headerValue,
message: "Header not found in expected headers",
});
continue; // Skip to next header
}
const expectedValue = expectedHeaders[headerName];
// Simple value comparison (can be extended for more complex checks)
if (headerValue !== expectedValue) {
anomalies.push({
header: headerName,
value: headerValue,
expected: expectedValue,
message: "Header value mismatch",
});
}
}
}
return anomalies;
}
// Example usage:
// const actualHeaders = {
// "Content-Type": "application/json",
// "X-Custom-Header": "someValue",
// "Authorization": "Bearer abcdef12345"
// };
// const expectedHeaders = {
// "Content-Type": "application/json",
// "Authorization": "Bearer abcdef12345"
// };
// const anomalies = flagHeaderAnomalies(actualHeaders, expectedHeaders);
// console.log(anomalies);
Add your comment