I’m trying to learn about developing a custom plugin and have found several articles people have written showing how to begin with a simple example. I’ve taken the example schema.lua and handler.lua files and am able to load these into Kong and apply the plugin to a test service. However, they both seem to fail when attempting to access the request object, for example:
self.echo_string = kong.request.get_header(conf.requestHeader)
In the Kong log is this error message:
2019/10/25 18:39:50 [error] 24#0: *2316 lua coroutine: runtime error: .../custom/kong/plugins/kong-plugin-header-echo/handler.lua:20: attempt to index field 'request' (a nil value)
This would seem to indicate that the ‘request’ object is invalid or that it cannot be used in this manner. I’ve read through the Kong documentation about writing handler.lua, but it doesn’t go into details about the inherent objects with which your code would interact. The suggested link to code for the key-auth plugin shows this using the kong.request object, but not using a get_header() method.
Are these inherent object types more fully documented somewhere? I’m trying this with Kong EE 0.34-1.