Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Using ExtractVariable policy to extract HTTP header and printing on console using JavaScript

Hi,

I'm very new to APIGEE and have been going through 4MV4D by Anil to try out some scenarios. My scenario is very simple.

I have created a "Reverse Proxy" and mapped it to httpbin.org/get as target. I'm trying to use ExtractVariable policy to extract the "Content-Encoding" HTTP header and use a JavaScript policy to print to the console.

Here's my code from "ExtractVariable" policy:

....

<Header name="Content-Encoding">  
    <Pattern ignoreCase="true">CE {response.header.Content-Encoding}</Pattern>  
</Header>
<Source clearPayload="false">response</Source>

....

This is what I'm using to print to the console using JavaScript

print(context.getVariable("CE"));

Both the "ExtractVariable" policy and JavaScript policy is applied to the response path of the Pre-Flow.

The proxy executes successfully and I get a 200 OK and a successful response back in the browser, however, I'm seeing null being printed on the console.

What am I missing here? Can anyone please suggest?

0 1 184
1 REPLY 1