aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2023-02-09 22:58:01 +0000
committerMatthew Wild <mwild1@gmail.com>2023-02-09 22:58:01 +0000
commitfbfe255e12c980024d4147a77c5de1c3f727016c (patch)
tree76272fd2c00ff66e34a373bfda1a1cd430e51adb /net
parent8bc31437bc1431ca13f1f96e3ddf52633fa99303 (diff)
parent0fd88a07a4951d6e06e20f7c3dcc5c115cd78ace (diff)
downloadprosody-fbfe255e12c980024d4147a77c5de1c3f727016c.tar.gz
prosody-fbfe255e12c980024d4147a77c5de1c3f727016c.zip
Merge 0.12->trunk
Diffstat (limited to 'net')
-rw-r--r--net/http.lua2
-rw-r--r--net/http/parser.lua17
2 files changed, 12 insertions, 7 deletions
diff --git a/net/http.lua b/net/http.lua
index 332ee250..aa435719 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -94,7 +94,7 @@ local function request_reader(request, data, err)
r.body_length and ("%d bytes"):format(r.body_length) or "unknown length"
);
if request.streaming_handler then
- log("debug", "Request '%s': Streaming via handler");
+ log("debug", "Request '%s': Streaming via handler", request.id);
r.body_sink, finalize_sink = request.streaming_handler(r);
end
return;
diff --git a/net/http/parser.lua b/net/http/parser.lua
index 7fbade4c..b95d9017 100644
--- a/net/http/parser.lua
+++ b/net/http/parser.lua
@@ -130,10 +130,13 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
partial = true;
};
end
- if len and len > bodylimit then
+ if not len or len > bodylimit then
-- Early notification, for redirection
success_cb(packet);
- if not packet.body_sink then error = true; return error_cb("content-length-limit-exceeded"); end
+ if not packet.body_sink and (len and len > bodylimit) then
+ error = true;
+ return error_cb("content-length-limit-exceeded");
+ end
end
if chunked and not packet.body_sink then
success_cb(packet);
@@ -174,9 +177,11 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
end
elseif packet.body_sink then
local chunk = buffer:read_chunk(len);
- while chunk and len > 0 do
+ while chunk and (not len or len > 0) do
if packet.body_sink:write(chunk) then
- len = len - #chunk;
+ if len then
+ len = len - #chunk;
+ end
chunk = buffer:read_chunk(len);
else
error = true;
@@ -188,9 +193,9 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
packet.partial = nil;
success_cb(packet);
end
- elseif buffer:length() >= len then
+ elseif not len or buffer:length() >= len then -- or not len
assert(not chunked)
- packet.body = buffer:read(len) or "";
+ packet.body = len and buffer:read(len) or buffer:read_chunk() or "";
state = nil;
packet.partial = nil;
success_cb(packet);