# HG changeset patch # User jbe # Date 1434676198 -7200 # Node ID a79ed835b6de9f163caac6b69bc2d7842352d3c6 # Parent f0dc143f510adc629fae7e16265185acdfbb1122 Code cleanup in HTTP module diff -r f0dc143f510a -r a79ed835b6de moonbridge_http.lua --- a/moonbridge_http.lua Fri Jun 19 02:03:18 2015 +0200 +++ b/moonbridge_http.lua Fri Jun 19 03:09:58 2015 +0200 @@ -416,16 +416,12 @@ end -- function to report an error: local function request_error(throw_error, status, text) - local errmsg = "Error while reading request from client. Error response: " .. status - if text then - errmsg = errmsg .. " (" .. text .. ")" - end if state == "init" or state == "no_status_sent" or state == "info_status_sent" then - local error_response_status, errmsg2 = pcall(function() + local error_response_status, errmsg = pcall(function() request:monologue() request:send_status(status) request:send_header("Content-Type", "text/plain") @@ -437,16 +433,17 @@ end) if not error_response_status then if text then - error("Error while sending error response (" .. status .. " / " .. text .. "): " .. errmsg2) + error("Error while sending error response (" .. status .. " / " .. text .. "): " .. errmsg) else - error("Error while sending error response (" .. status .. "): " .. errmsg2) + error("Error while sending error response (" .. status .. "): " .. errmsg) end end - elseif state ~= "faulty" then - state = "faulty" - assert_close(socket:reset()) end if throw_error then + local errmsg = "Error while reading request from client. Error response: " .. status + if text then + errmsg = errmsg .. " (" .. text .. ")" + end error(errmsg) else return survive @@ -478,18 +475,18 @@ return data end -- reads a number of bytes from the socket, - -- optionally feeding these bytes chunk-wise - -- into a callback function: + -- optionally feeding these bytes chunk-wise into + -- the "process_body_chunk" callback function: local function read_body_bytes(remaining) while remaining > 0 do - local limit + local chunklen if remaining > input_chunk_size then - limit = input_chunk_size + chunklen = input_chunk_size else - limit = remaining + chunklen = remaining end - local chunk = read(limit) - remaining = remaining - limit + local chunk = read(chunklen) + remaining = remaining - chunklen if process_body_chunk then process_body_chunk(chunk) end