How to retrieve the hostname used in the request ?

We need your assistance in retrieving the hostname value in the API proxy.


We notice that Host is fetched in the trace when API call is made as part of the Request Headers

... 
Host myhost.domain.com
...
	

However, when I try to read the value of the variable "request.header.host" I get the value as mocktarget.apigee.net instead of myhost.domain.com.

0 2 2,895
2 REPLIES 2

1. Looking at the Proxy bundle, it was noticed that the user was fetching the request.header.Host variable in the JS policy named JS-logging in the response flow.

2. During the execution of the API Proxy, the request.header.Host will get modified to point to the target host name and hence the header request.header.Host returned the value as mocktarget.apigee.net.

3. To retain the host name that was originally passed to the API Proxy, we can have the JS policy in the request flow and store the value of request.header.Host in another variable.

For ex:

var request_host = context.getVariable("request.header.Host"); 
context.setVariable("request_host", request_host);

The variable "request_host" can later be used in JS-logging policy in the response flow.

Note: You could also use AssignMessage Policy to store the value for request.header.Host to some other variable.

The problem though is when you need to process it for the response and create a common shared flow. Will end up creating two shared flows with mutual dependency