Kong/kong-python-pdk

Unable to set QueryString in Custom Plugin access phase

sivasubramani300890 opened this issue · 6 comments

Hi Team,
I am trying to get query string using "kong.request.get_raw_query()" and after changing to right values setting the query string using "kong.service.request.set_raw_query(queryString)".But it is not happening.

Using python to develop third party plugin

Hi @sivasubramani300890 kong.request and kong.service.request are two different objects,
the former is what Kong sees from client request, the later is what upstream ("Service") sees from Kong's request

client --------------> kong -------------> upstream
             ^                                   ^
        kong.request                 kong.service.request

Hi @fffonion , Thanks for your response. I understood your explanation. The problem is when i am trying to setup new path instead of existing path in upstream its not considering

for example :

Existing path : www.abc.com/v1/data
New Path : www.abc.com/v2/data?key=value

Tried using kong.service.request.set_path("NewPath"),but didn't worked

@sivasubramani300890 might consider use kong.service.request.set_raw_query to set query instead of
the path.

@fffonion kong.service.request.set_raw_query is working for only setting up querystring(data=value), but unable to change path.Please refer below example

Existing Path : www.abc.com/v1/data?data=value
New Path : www.abc.com/v2/data?datanew=valuenew

@sivasubramani300890 you will then need kong.service.request.set_path to set the path and kong.service.request.set_raw_query to set the query.

Hi @fffonion ,Thanks for the response.set_path is working fine but it was not working earlier.Anyway Thanks for quick response