diff options
-rw-r--r-- | default.lua | 7 | ||||
-rw-r--r-- | stream.c | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/default.lua b/default.lua index dc4237e..ab15a95 100644 --- a/default.lua +++ b/default.lua @@ -1,7 +1,14 @@ --- Default client request handler. -- TODO: Add documentation once request and response API are more stable. return function (stream) + local method, path, version, h = stream:read " ", stream:read " ", stream:read "\r\n", stream:read "\r\n\r\n" + local headers = {} + for header, value in h:gmatch "([^%s:]+)%s*:%s+([^\r\n]*)" do + headers[header:lower()] = value + end + 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} end @@ -114,7 +114,7 @@ static int until(struct buffer * b, const char * pattern, const int pattern_leng { int offset = b->offset; - while (offset + pattern_length < b->length) + while (offset + pattern_length <= b->length) { if (0 == strncmp(&b->data[offset], pattern, pattern_length)) { |