It would be nice if dnsdist supported adding an API HTTP handler in Lua.
Usecase
This would allow HTTP clients to update the Lua configuration in arbitrary - but controlled - ways without having to implement custom API endpoints for every possible feature. Currently this can only be achieved by opening a socket to the dnsdist console and writing Lua function calls to it.
Description
For example, dnsdist could define a /api/v1/servers/localhost/custom[/....] endpoint that is handled in Lua. When an HTTP request is received, dnsdist calls a user-defined customhttphandler Lua function to handle the request.
The request object would be a table for easy future extensibility without an explosion of positional arguments. Suggested attributes to include in the request object:
method: the HTTP method
path: the full request path
body: the raw request body as string
params: parsed GET params
form: parsed POST values if this is a POST request and the content type is application/x-www-form-urlencoded
subpath: the subpath under /api/v1/servers/localhost/custom, allowing for custom routing in Lua.
The response args are:
The HTTP status code
An optional table of extra HTTP headers to set on the response (nil allowed)
A string with the response contents
In order to limit the time spent in the Lua code (which will block dnsdist), dnsdist buffers the whole request with body before calling the Lua code. This processing is all done in a separate thread. For the same reason, the Lua handler returns the whole response at once, instead of streaming the response as is common in modern frameworks.
If the customhttphandler callback is not defined, dnsdist returns a 404 and an appropriate message.
The HTTP request is subject to API key validation.
The text was updated successfully, but these errors were encountered:
Short description
It would be nice if dnsdist supported adding an API HTTP handler in Lua.
Usecase
This would allow HTTP clients to update the Lua configuration in arbitrary - but controlled - ways without having to implement custom API endpoints for every possible feature. Currently this can only be achieved by opening a socket to the dnsdist console and writing Lua function calls to it.
Description
For example, dnsdist could define a
/api/v1/servers/localhost/custom[/....]
endpoint that is handled in Lua. When an HTTP request is received, dnsdist calls a user-definedcustomhttphandler
Lua function to handle the request.The Lua callback function could look as follows:
The request object would be a table for easy future extensibility without an explosion of positional arguments. Suggested attributes to include in the request object:
application/x-www-form-urlencoded
/api/v1/servers/localhost/custom
, allowing for custom routing in Lua.The response args are:
In order to limit the time spent in the Lua code (which will block dnsdist), dnsdist buffers the whole request with body before calling the Lua code. This processing is all done in a separate thread. For the same reason, the Lua handler returns the whole response at once, instead of streaming the response as is common in modern frameworks.
If the
customhttphandler
callback is not defined, dnsdist returns a 404 and an appropriate message.The HTTP request is subject to API key validation.
The text was updated successfully, but these errors were encountered: