Sunday, January 1, 2023

Kong Plugin Implementing custom Logic

A Kong Gateway plugin allows you to inject custom logic (in Lua) at several entry-points in the life-cycle of a request/response or a tcp stream connection as it is proxied by Kong Gateway. To do so, the file kong.plugins.<plugin_name>.handler must return a table with one or more functions with predetermined names. Those functions will be invoked by Kong Gateway at different phases when it processes traffic.


The first parameter they take is always self. All functions except init_worker can receive a second parameter which is a table with the plugin configuration.


main entry points are


init_worker

certificate

rewrite

access -> Executed for every request from a client and before it is being proxied to the upstream service.

ws_handshake -> Executed for every request to a WebSocket service just before completing the WebSocket handshake.

response -> Executed after the whole response has been received from the upstream service, but before sending any part of it to the client.

header_filter -> Executed when all response headers bytes have been received from the upstream service.

ws_client_frame -> Executed for each WebSocket message received from the client.

ws_upstream_frame -> Executed for each WebSocket message received from the upstream service

body_filter -> Executed for each chunk of the response body received from the upstream service. Since the response is streamed back to the client, it can exceed the buffer size and be streamed chunk by chunk. This function can be called multiple times if the response is large

log -> Executed when the last response byte has been sent to the client.

ws_close -> Executed after the WebSocket connection has been terminated.

 


references:

https://docs.konghq.com/gateway/latest/plugin-development/custom-logic/ 

No comments:

Post a Comment