From 7bac9cfb5788eea26b940b4be691d1f80b6d1deb Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 15 Aug 2020 19:44:26 +0200 Subject: Implemented content length parsing --- request.c | 16 ++++++++++++++++ request.h | 1 + 2 files changed, 17 insertions(+) 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 *); -- cgit v1.1