Hi, I am trying to obtain the IP address of the sender in the Tyk middleware using python. I read up on the request context variables here which mentioned that the header ‘x-remote-addr’ would be available.
However, in the python middleware code, I tried printing out the headers in the def PostKeyAuth(request, session, spec) hook using tyk.log("Request: " + str(request.dict), “info”) but could not find that header. Is there anything I missed?
The fist thing to check that that X-Remote-Addr is being populated. For this I pointed my API at http:/httpbin.org/get and checked it’s reply.
Assuming you’re seeing X-Remote-Addr populated, the next thing to check is that you’re calling your python plugin late enough in the middleware sequence to make sure tyk has populated the header.
Request Middleware Chain gives a nice diagram of when different things happen as the request makes its way through the gateway. I’ve put my plugin in the ‘post’ section.
If you’re still having trouble. Please let us know what version of the gateway you are trying (I’m using 3.0.9 which is the current long term support) and also please upload your API definition so we can have a look at that too.