Called when a new subscriber connects. It provides a single argument sub
which is a Lua table containing context of the subscribe request. The function is free to modify the request however it needs, but it must return it (modified or not) to the server or the connection will be rejected with a 403 Forbidden
error and the client will be disconnected immediately.
NOTE: Changes to the inner req
table will not be preserved.
function subscribe(sub)
-- The `sub` table looks like:
{
req = {
query = "",
headers = {
["user-agent"] = "curl/8.7.1",
accept = "*/*",
host = "127.0.0.1:1983"
},
path = "/sse",
addr = {
ip = "127.0.0.1",
port = 59632
},
method = "GET"
}
}
-- The function is free to modify this table however it needs, but it
-- must return it to the server or the subscribe request will be rejected.
return sub
end