aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-10-21 10:34:16 +0100
committerMatthew Wild <mwild1@gmail.com>2020-10-21 10:34:16 +0100
commitbc402b6409639f130f2ef7f13c9e240194de859c (patch)
treeeb5cd64c61e8c996443d93ce662b1eaa589e7171
parent5b33f834fa2159a74cf0f80922f67b5e1f18a4d7 (diff)
downloadprosody-bc402b6409639f130f2ef7f13c9e240194de859c.tar.gz
prosody-bc402b6409639f130f2ef7f13c9e240194de859c.zip
net.http.parser: Expose 'partial', 'chunked' and 'body_length' on packets
-rw-r--r--net/http/parser.lua17
1 files changed, 15 insertions, 2 deletions
diff --git a/net/http/parser.lua b/net/http/parser.lua
index 3470ffb1..96f17fdb 100644
--- a/net/http/parser.lua
+++ b/net/http/parser.lua
@@ -47,6 +47,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
if state and client and not len then -- reading client body until EOF
buffer:collapse();
packet.body = buffer:read_chunk() or "";
+ packet.partial = nil;
success_cb(packet);
state = nil;
elseif buffer:length() ~= 0 then -- unexpected EOF
@@ -96,6 +97,9 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
httpversion = httpversion;
headers = headers;
body = false;
+ body_length = len;
+ chunked = chunked;
+ partial = true;
-- COMPAT the properties below are deprecated
responseversion = httpversion;
responseheaders = headers;
@@ -122,6 +126,8 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
headers = headers;
body = false;
body_sink = nil;
+ chunked = chunked;
+ partial = true;
};
end
if len and len > bodylimit then
@@ -157,6 +163,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
buf = buf:gsub("^.-\r\n\r\n", ""); -- This ensure extensions and trailers are stripped
buffer:write(buf);
state, chunked = nil, nil;
+ packet.partial = nil;
success_cb(packet);
elseif buffer:length() - chunk_start - 2 >= chunk_size then -- we have a chunk
buffer:discard(chunk_start - 1); -- TODO verify that it's not off-by-one
@@ -176,11 +183,17 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
return error_cb("body-sink-write-failure");
end
end
- if len == 0 then state = nil; success_cb(packet); end
+ if len == 0 then
+ state = nil;
+ packet.partial = nil;
+ success_cb(packet);
+ end
elseif buffer:length() >= len then
assert(not chunked)
packet.body = buffer:read(len) or "";
- state = nil; success_cb(packet);
+ state = nil;
+ packet.partial = nil;
+ success_cb(packet);
else
break;
end