diff options
author | Aki <please@ignore.pl> | 2020-08-15 19:44:26 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2020-08-15 19:50:30 +0200 |
commit | 7bac9cfb5788eea26b940b4be691d1f80b6d1deb (patch) | |
tree | 875f6f5fcfd2acd8df894d8f59bd87ce8282c310 | |
parent | 41cb74fa129f5e18b6c0b99b89933869f09b585c (diff) | |
download | plop-7bac9cfb5788eea26b940b4be691d1f80b6d1deb.zip plop-7bac9cfb5788eea26b940b4be691d1f80b6d1deb.tar.gz plop-7bac9cfb5788eea26b940b4be691d1f80b6d1deb.tar.bz2 |
Implemented content length parsing
-rw-r--r-- | request.c | 16 | ||||
-rw-r--r-- | request.h | 1 |
2 files changed, 17 insertions, 0 deletions
@@ -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. @@ -23,6 +23,7 @@ struct request lua_State * lua; int reference; struct span temp; + int expected_data_length; }; struct request * new_request(lua_State *); |