We are trying to look at all the headers returned from the target server's input.
In the Proxy Post Flow, we have a JavaScript Policy. It loops through the response.headers and print's out the headers.
print("Headers Loop") for (var n in response.headers) { print(n + " --> " + response.headers[n]); }
The header for Access-Control-Allow-Headers that comes from the target endpoint contains multiple values (comma-delimited): "origin,x-requested-with,accept,ucsb-api-key,authorization"
But, in the JavaScript policy, when we are trying to access that information only "origin" is returned as a value.
How can we ensure that the headers in the JavaScript policy matches with the response headers received from the target server ?
Solved! Go to Solution.
Since some of the response headers has multiple values, we need to use a different variable response.header.{header_name}.values to get all the values from the response header as documented in Variables Reference.
Here's the JavaScript code that can help to get all the values
var headerNames = context.getVariable('response.headers.names'); //convert it to string array. headerNames = headerNames.toArray(); for (var i = 0; i < headerNames.length; i++) { var values = 'response.header.'+headerNames[i]+'.values'; var headerValues = context.getVariable(values) + ''; print("headerValues = " + headerValues); // get the array of header values by removing the square brackets var strHeaderValues = headerValues.substring(1, headerValues.length-1).split(','); print("strHeaderValues = " + strHeaderValues); print(headerNames[i] + ":" + strHeaderValues); }
With this code, I was able to list the multi values the response headers and multi values as well.
Since some of the response headers has multiple values, we need to use a different variable response.header.{header_name}.values to get all the values from the response header as documented in Variables Reference.
Here's the JavaScript code that can help to get all the values
var headerNames = context.getVariable('response.headers.names'); //convert it to string array. headerNames = headerNames.toArray(); for (var i = 0; i < headerNames.length; i++) { var values = 'response.header.'+headerNames[i]+'.values'; var headerValues = context.getVariable(values) + ''; print("headerValues = " + headerValues); // get the array of header values by removing the square brackets var strHeaderValues = headerValues.substring(1, headerValues.length-1).split(','); print("strHeaderValues = " + strHeaderValues); print(headerNames[i] + ":" + strHeaderValues); }
With this code, I was able to list the multi values the response headers and multi values as well.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |