From 06924d10f6f92997096a156701e409ad9725d2c0 Mon Sep 17 00:00:00 2001 From: Luna Date: Tue, 6 Dec 2022 14:52:20 -0300 Subject: [PATCH] let filters customize status code and body --- main.lua | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/main.lua b/main.lua index 71699f6..dd25def 100644 --- a/main.lua +++ b/main.lua @@ -43,14 +43,12 @@ local function onRequest() log('AWOOOOGA') for _,tuple in ipairs(callbacks_to_call) do - local callback_function, config = tuple[1], tuple[2] - local result, body = callback_function(config) - log(result) - log(body) - if not result then - ngx.status = 400 + local callback_function, config, state = unpack(tuple) + local status_code, body = callback_function(config, state) + if status_code ~= nil then + ngx.status = status_code ngx.say(body or "request denied") - ngx.exit(400) + ngx.exit(status_code) end end end