summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-08-16 19:01:00 +0200
committerAki <please@ignore.pl>2020-08-16 19:01:00 +0200
commitc5daa4e7bbd0e4f8d222daa9db13165e7fe4fb9a (patch)
tree7be6283e4b53e2e0696bd076bdb1d793750b7f52
parentd41fa3a7b62216e35cc5a7be665f80481b6f9c78 (diff)
downloadplop-c5daa4e7bbd0e4f8d222daa9db13165e7fe4fb9a.zip
plop-c5daa4e7bbd0e4f8d222daa9db13165e7fe4fb9a.tar.gz
plop-c5daa4e7bbd0e4f8d222daa9db13165e7fe4fb9a.tar.bz2
Changed to use Lua based response for errors
-rw-r--r--plop.c18
1 files 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);