Why not calling kong.response.exit(4xx)? What is the difference you are seeing between the nominal and non-nominal use cases?
Well, one returns a data and the other one not… but you’re right, that the same !
So, I used kong.response.exit everywhere, and it is working fine… except in the piece of code corresponding to a plugin api: in this case, I’m receiving an exception
2018/09/11 12:54:10 [error] 39#0: *569 lua coroutine: runtime error: /usr/local/share/lua/5.1/kong/pdk/private/phases.lua:64: no phase in kong.ctx.core.phase
stack traceback:
coroutine 0:
[C]: in function 'error'
/usr/local/share/lua/5.1/kong/pdk/private/phases.lua:64: in function 'check_phase'
/usr/local/share/lua/5.1/kong/pdk/response.lua:544: in function </usr/local/share/lua/5.1/kong/pdk/response.lua:543>
coroutine 1:
[C]: in function 'resume'
/usr/local/share/lua/5.1/lapis/application.lua:393: in function 'handler'
/usr/local/share/lua/5.1/lapis/application.lua:130: in function 'resolve'
/usr/local/share/lua/5.1/lapis/application.lua:161: in function </usr/local/share/lua/5.1/lapis/application.lua:159>
[C]: in function 'xpcall'
/usr/local/share/lua/5.1/lapis/application.lua:159: in function 'dispatch'
/usr/local/share/lua/5.1/lapis/nginx.lua:215: in function 'serve_admin_api'
content_by_lua(nginx-kong.conf:246):2: in function <content_by_lua(nginx-kong.conf:246):1>, client: 10.129.2.1, server: kong_admin
So for this use case, I’m still using return helpers.responses.send_HTTP_OK() instead.
Regarding the PDK usage in general, I tried to replace all references to ngx. inside the code of my plugins. OK for for getting data from the request and setting on the response; OK for setting data on the upstream request and getting data from the upstream response; here are the ngx. usages that remain in my code:
- The HTTP error codes:
ngx.OK,ngx.HTTP_UNAUTHORIZED…, because I still prefer using constants instead of raw numbers. ngx.redirectfor redirecting the incoming callngx.var.<proprietary variable>: ok, that’s fully proprietary variables; I’m not expecting the PDK to give me a shortcut to that
- And then some other misc functions that are most likely not eligible to be provided in the PDK:
ngx.encode_args(I don’t know if it would be better for me to use the function present inkong.utils.lua…),ngx.decode_base64,ngx.time,ngx.re