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