summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--default.lua2
-rw-r--r--plop.c14
3 files changed, 16 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 68c7d65..26bb34c 100644
--- a/Makefile
+++ b/Makefile
@@ -5,12 +5,13 @@ LDLIBS+=-llua5.3
PREFIX?=/usr/local
SHARE?=$(PREFIX)/share
-plop: connection.o main.o plop.o stream.o
+plop: connection.o main.o plop.o stream.o response.o
main.o: plop.h
plop.o: connection.h plop.h stream.h
connection.o: connection.h
stream.o: stream.h
+response.o: response.h
clean:
rm -f plop *.o
diff --git a/default.lua b/default.lua
index 95ba609..dc4237e 100644
--- a/default.lua
+++ b/default.lua
@@ -1,6 +1,6 @@
--- Default client request handler.
-- TODO: Add documentation once request and response API are more stable.
-return function (method, path, version, headers, data)
+return function (stream)
local response_data = [["Hello from plop/lua!"]]
local headers = {Connection="close", ["Content-Length"]=#response_data, ["Content-Type"]="application/json"}
return {status=200, headers=headers, data=response_data}
diff --git a/plop.c b/plop.c
index 980ce90..7859e7b 100644
--- a/plop.c
+++ b/plop.c
@@ -17,6 +17,7 @@
#include "connection.h"
#include "stream.h"
+#include "response.h"
/// Initializes new Lua state for the server.
/// \return Lua state
@@ -158,20 +159,31 @@ int plop_handle_client(lua_State * L, struct epoll_event * event)
}
int result = lua_resume(c->L, NULL, nargs);
- connection_free(L, c); // TODO: Allow consistent connections?
switch (result)
{
case LUA_OK:
{
+ int n = lua_gettop(c->L);
+
+ if (0 == n)
+ {
+ lua_pushnil(c->L);
+ }
+
+ response_send(c->L, c->fd);
+ connection_free(L, c);
+
return 0;
}
case LUA_YIELD:
{
+ connection_free(L, c); // TODO: This shouldn't be the case... Right?
return 0;
}
default:
{
+ connection_free(L, c);
return -1;
}
}