summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-08-15 19:44:26 +0200
committerAki <please@ignore.pl>2020-08-15 19:50:30 +0200
commit7bac9cfb5788eea26b940b4be691d1f80b6d1deb (patch)
tree875f6f5fcfd2acd8df894d8f59bd87ce8282c310
parent41cb74fa129f5e18b6c0b99b89933869f09b585c (diff)
downloadplop-7bac9cfb5788eea26b940b4be691d1f80b6d1deb.zip
plop-7bac9cfb5788eea26b940b4be691d1f80b6d1deb.tar.gz
plop-7bac9cfb5788eea26b940b4be691d1f80b6d1deb.tar.bz2
Implemented content length parsing
-rw-r--r--request.c16
-rw-r--r--request.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/request.c b/request.c
index 7902f1f..e0956b4 100644
--- a/request.c
+++ b/request.c
@@ -281,6 +281,12 @@ int parse_step_header_name(struct request * request)
request->temp.length = request->position - request->temp.start;
+ if (0 == strncasecmp("content-length", request->data + request->temp.start, request->temp.length))
+ {
+ // TODO: While it shouldn't happen, use a flag instead of a magic value.
+ request->expected_data_length = -1;
+ }
+
lua_pushlstring(request->lua, request->data + request->temp.start, request->temp.length);
// Skip ':'
@@ -312,8 +318,18 @@ int parse_step_header_value(struct request * request)
request->temp.length = request->position - request->temp.start;
+ if (-1 == request->expected_data_length)
+ {
+ *(request->data + request->temp.start + request->temp.length) = 0;
+ request->expected_data_length = atoi(request->data + request->temp.start);
+ *(request->data + request->temp.start + request->temp.length) = '\r';
+ }
+
lua_pushlstring(request->lua, request->data + request->temp.start, request->temp.length);
lua_rawset(request->lua, -3);
PROCEED_TO(parse_step_header_name);
}
+
+// TODO: Pass data payload to Lua state.
+// TODO: Make a table from the request.
diff --git a/request.h b/request.h
index 26284f0..723908f 100644
--- a/request.h
+++ b/request.h
@@ -23,6 +23,7 @@ struct request
lua_State * lua;
int reference;
struct span temp;
+ int expected_data_length;
};
struct request * new_request(lua_State *);