This code works for me to examine all the request headers:
// reflectHeaders.js
// ------------------------------------------------------------------
//
// formats the request headers into a JSON response.
//
// created: Tue May 13 11:42:19 2014
// last saved: <2014-May-13 12:05:39>
var requestHeaders = context.getVariable("request.headers.names"),
result = {};
// requestHeaders is a java.util.TreeMap$KeySet; convert it to string
requestHeaders = requestHeaders + '';
// convert from "[A, B, C]" to an array of strings: ["A", "B", "C"]
requestHeaders = requestHeaders.slice(1, -1).split(', ');
// insert each header into the response
requestHeaders.forEach(function(x){
var a = context.getVariable("request.header." + x );
result[x] = a;
});
// set the response content:
context.setVariable('response.content', JSON.stringify(result, null, 2));
If you like, here is a complete proxy bundle that shows how to use this JS. Just deploy it into an Apigee org and invoke it like this:
curl -H x-custom-header:my-custom-value http://ORG-ENV.apigee.net/v1/ex-js-header
output:
{
"Accept": "*/*",
"Host": "ORG-ENV.apigee.net",
"User-Agent": "curl/7.30.0",
"x-custom-header": "my-custom-value"
}