From c5daa4e7bbd0e4f8d222daa9db13165e7fe4fb9a Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 16 Aug 2020 19:01:00 +0200 Subject: Changed to use Lua based response for errors --- plop.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plop.c b/plop.c index da51251..43f9ed4 100644 --- a/plop.c +++ b/plop.c @@ -128,14 +128,18 @@ int handle_client(lua_State * L, struct epoll_event * event) if (-1 == parse_request(L, (*request)->fd, request)) { - respond_only_status((*request)->fd, STATUS_BAD_REQUEST); - return -1; // TODO: Handle errors properly + lua_newtable((*request)->lua); + lua_pushstring((*request)->lua, "status"); + lua_pushinteger((*request)->lua, 400); // TODO: How about a function that generates error responses? + lua_rawset((*request)->lua, -3); + } + else // TODO: 0 may mean EAGAIN, stuff will be bad very soon from here. + { + // TODO: Push the handler to stack earlier to avoid shifting it. + lua_getglobal((*request)->lua, "handler"); + lua_insert((*request)->lua, 1); + lua_call((*request)->lua, 5, 1); } - - // TODO: Push the handler to stack earlier to avoid shifting it. - lua_getglobal((*request)->lua, "handler"); - lua_insert((*request)->lua, 1); - lua_call((*request)->lua, 5, 1); int result = response_send((*request)->lua, (*request)->fd); -- cgit v1.1