Put header information of request into the Body of the request?

HI,

I want to add the header information to the body of the data/request that I make to the api.
For example I want to pick the source IP of the request and add that to the Body of the request with the other fields that I am posting as a Json request. So that now my request data will contain the ip of the request source.

Regards,
Anjna Bhati

Hi Anjna,

You would need to do that with some JS middleware, as the headers are not exposed to the body template transformer yet.

Cheers,
Martin

Hi Martin,
I did try with JS MIddleware but the header does not contain the source ip.
Is there any configuration missing?

Ah, I don’t think the IP is sent by default as a header, you might want to check for an X-Forwarded-For header if you are behind a load balancer, Tyk uses the raw TCP Remote Address from the request or the XFF when it grabs the ip:

If you are running Tyk behind something like NginX or HAProxy you might be able to add it in.

So I can assume that tyk has to run behind a load balancer to get the source ip.
Thank you :slight_smile:

Regards,
Anjna Bhati

1 Like