From 0643a6bde5cf0e1d9e24023919252a8d2085316a Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 10 Nov 2014 14:47:33 -0500 Subject: net.http.parser: Fix chunked encoding parsing across packet boundaries. --- net/http/parser.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/http/parser.lua b/net/http/parser.lua index d896dff4..056d4b60 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -132,7 +132,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) state, chunk_size = nil, nil; buf = buf:gsub("^.-\r\n\r\n", ""); -- This ensure extensions and trailers are stripped success_cb(packet); - elseif #buf - chunk_start + 2 >= chunk_size then -- we have a chunk + elseif #buf - chunk_start - 2 >= chunk_size then -- we have a chunk packet.body = packet.body..buf:sub(chunk_start, chunk_start + (chunk_size-1)); buf = buf:sub(chunk_start + chunk_size + 2); chunk_size, chunk_start = nil, nil; -- cgit v1.2.3 From a7d88ea2334bf18857b50cf7032ec3a3a79762fa Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 18 Nov 2014 17:40:37 +0000 Subject: net.http.parser: Fix whitespace/indentation --- net/http/parser.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/http/parser.lua b/net/http/parser.lua index 056d4b60..6d7187da 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -140,11 +140,11 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) break; end elseif len and #buf >= len then - if packet.code == 101 then - packet.body, buf = buf, "" - else - packet.body, buf = buf:sub(1, len), buf:sub(len + 1); - end + if packet.code == 101 then + packet.body, buf = buf, ""; + else + packet.body, buf = buf:sub(1, len), buf:sub(len + 1); + end state = nil; success_cb(packet); else break; -- cgit v1.2.3