From 6197a802f0267b7bb8c76d94c932a96825f381dd Mon Sep 17 00:00:00 2001 From: Parth Verma Date: Tue, 30 Jul 2024 18:12:15 -0700 Subject: [PATCH] Added proxy over deprecated responseHeaders to make object case-insensitive --- lib/sandbox/postman-legacy-interface.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/sandbox/postman-legacy-interface.js b/lib/sandbox/postman-legacy-interface.js index d718d898..5dd38aaf 100644 --- a/lib/sandbox/postman-legacy-interface.js +++ b/lib/sandbox/postman-legacy-interface.js @@ -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) { @@ -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.} */ - 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