Javascript access to headers added to request?

Not applicable

I have a JS policy that triggers an HTTP request to an external log aggregator, with information about the incoming request and the response. The policy runs in the JS proxy post flow.

The JS is able to pick up incoming request headers with a call like

context.proxyRequest.headers["X-Incoming-ID"]

However, we add additional headers to the request as it passes through the pre flow, which I would also like to capture. These values are coming back empty, so it appears that context.proxyRequest does not access them. Is there a way I can access these values from the JS proxy post flow?

Solved Solved
0 2 14K
1 ACCEPTED SOLUTION

hi @pblair; I usually capture the request variable and save it to context in proxy PreFlow; e.g.

var X_Incoming_ID = context.getVariable('request.header.X-Incoming-ID');
context.setVariable("X_Incoming_ID", X_Incoming_ID);

and use this `X_Incoming_ID` variable wherever want to to refer;

context.getVariable("X_Incoming_ID");

Also, note I use `context.getVariable('request.header.X-Incoming-ID')` not sure what context.proxyRequest.headers does 😐

View solution in original post

2 REPLIES 2

hi @pblair; I usually capture the request variable and save it to context in proxy PreFlow; e.g.

var X_Incoming_ID = context.getVariable('request.header.X-Incoming-ID');
context.setVariable("X_Incoming_ID", X_Incoming_ID);

and use this `X_Incoming_ID` variable wherever want to to refer;

context.getVariable("X_Incoming_ID");

Also, note I use `context.getVariable('request.header.X-Incoming-ID')` not sure what context.proxyRequest.headers does 😐

There seems to be a problem in apigee when the header variable has a json content. The extracted value is terminated after the first field. I think, the string ends when it sees a coma. Looks like a bug in Apigee. The only way to validate json content in header is to receive it as encoded string. Has anybody faced this issue?