Skip to content

Commit

Permalink
Added proxy over deprecated responseHeaders to make object case-insen…
Browse files Browse the repository at this point in the history
…sitive
  • Loading branch information
parthverma1 committed Jul 31, 2024
1 parent cc0f575 commit 6197a80
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/sandbox/postman-legacy-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ const _ = require('lodash'),
URLENCODED: 'urlencoded',
FORMDATA: 'formdata',
FILE: 'file'
},

/**
* Proxy handler for response headers to make them case-insensitive.
*/
responseHeadersProxyHandler = {
get: (target, key) => {
if (key === 'hasOwnProperty') {
return (prop) => { return Reflect.has(target, prop.toLowerCase()); };
}

return target[key.toLowerCase()];
}
};

function getRequestBody (request) {
Expand Down Expand Up @@ -376,15 +389,18 @@ module.exports = {
globalvars.responseCookies = execution.cookies || [];

/**
* Stores the response headers with the keys being case sensitive
* Stores the response headers with case insensitive keys
*
* @memberOf SandboxGlobals
* @type {Array.<Object>}
*/
globalvars.responseHeaders = {};

const responseHeaders = {};

execution.response && execution.response.headers.each(function (header) {
header && !header.disabled && (globalvars.responseHeaders[header.key] = header.value);
header && !header.disabled && (responseHeaders[header.key.toLowerCase()] = header.value);
});
globalvars.responseHeaders = new Proxy(responseHeaders, responseHeadersProxyHandler);

/**
* @memberOf SandboxGlobals
Expand Down

0 comments on commit 6197a80

Please sign in to comment.