Python middleware request definition

Hi team,

I’m working on a custom auth Python middleware.
I want get the url of the request in the script. Is it included in the request object, and how to get it ?
I also want to get the source IP. I added the following global header in my API definition :

		"global_headers": {
		  "X-TYK-IP": "$tyk_context.remote_addr"

And enabled enable_context_vars setting. But request.get_header('X-Tyk-Ip') still return nothing.

Thanks !

1 Like

Hi, you can use request.object.request_uri to get the URL.

Accesing the values in global_headers isn’t currently possible when using a custom authentication middleware, the reason is that the middleware which injects global_headers runs after the authentication hook. However you should be able to access these values using a POST hook.

Currently it’s not possible to access the remote address using plugins but I will create a ticket with that feature suggestion.


I’ve created a ticket here.

1 Like