summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-02-25 21:25:59 +0100
committerAki <please@ignore.pl>2021-02-25 21:25:59 +0100
commit3a7f02075e2b613932b3673486b5538373232603 (patch)
tree08f04e826a4149776d94a6bb9a9e4e4f8e475a57
parentd2d8e8733c68c75097bac120162742ba4b15736b (diff)
downloadplop-3a7f02075e2b613932b3673486b5538373232603.zip
plop-3a7f02075e2b613932b3673486b5538373232603.tar.gz
plop-3a7f02075e2b613932b3673486b5538373232603.tar.bz2
Fixed comparison and extended example
-rw-r--r--default.lua7
-rw-r--r--stream.c2
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
diff --git a/stream.c b/stream.c
index cf92ad3..a4fb8c8 100644
--- a/stream.c
+++ b/stream.c
@@ -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))
{