# HG changeset patch # User Matthew Wild # Date 1675983481 0 # Node ID 0d5868a9e6416fed1ee1de30cea325d0017142db # Parent b56a2731bf00114aa53cceb34b3a7b62ccda060d# Parent 9ed628635dc66da3fdc28af836efcb1a6428fc95 Merge 0.12->trunk diff -r b56a2731bf00 -r 0d5868a9e641 net/http.lua --- a/net/http.lua Thu Feb 09 22:34:05 2023 +0000 +++ b/net/http.lua Thu Feb 09 22:58:01 2023 +0000 @@ -94,7 +94,7 @@ 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 -r b56a2731bf00 -r 0d5868a9e641 net/http/parser.lua --- a/net/http/parser.lua Thu Feb 09 22:34:05 2023 +0000 +++ b/net/http/parser.lua Thu Feb 09 22:58:01 2023 +0000 @@ -130,10 +130,13 @@ 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 @@ 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 @@ 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); diff -r b56a2731bf00 -r 0d5868a9e641 spec/net_http_parser_spec.lua --- a/spec/net_http_parser_spec.lua Thu Feb 09 22:34:05 2023 +0000 +++ b/spec/net_http_parser_spec.lua Thu Feb 09 22:58:01 2023 +0000 @@ -87,7 +87,7 @@ ]], { - body = "Hello", count = 2; + body = "Hello", count = 3; } ); end); @@ -116,7 +116,7 @@ ]], { - body = "Hello", count = 3; + body = "Hello", count = 4; } ); end); @@ -129,7 +129,7 @@ assert.equal("25930f021785ae14053a322c2dbc1897c3769720", sha1(data, true), "test data malformed"); test_stream(data, { - body = string.rep("~", 11085), count = 2; + body = string.rep("~", 11085), count = 3; }); end); end);