moonbridge

changeset 182:a79ed835b6de

Code cleanup in HTTP module
author jbe
date Fri Jun 19 03:09:58 2015 +0200 (2015-06-19)
parents f0dc143f510a
children 478d6237e17a
files moonbridge_http.lua
line diff
     1.1 --- a/moonbridge_http.lua	Fri Jun 19 02:03:18 2015 +0200
     1.2 +++ b/moonbridge_http.lua	Fri Jun 19 03:09:58 2015 +0200
     1.3 @@ -416,16 +416,12 @@
     1.4        end
     1.5        -- function to report an error:
     1.6        local function request_error(throw_error, status, text)
     1.7 -        local errmsg = "Error while reading request from client. Error response: " .. status
     1.8 -        if text then
     1.9 -          errmsg = errmsg .. " (" .. text .. ")"
    1.10 -        end
    1.11          if
    1.12            state == "init" or
    1.13            state == "no_status_sent" or
    1.14            state == "info_status_sent"
    1.15          then
    1.16 -          local error_response_status, errmsg2 = pcall(function()
    1.17 +          local error_response_status, errmsg = pcall(function()
    1.18              request:monologue()
    1.19              request:send_status(status)
    1.20              request:send_header("Content-Type", "text/plain")
    1.21 @@ -437,16 +433,17 @@
    1.22            end)
    1.23            if not error_response_status then
    1.24              if text then
    1.25 -              error("Error while sending error response (" .. status .. " / " .. text .. "): " .. errmsg2)
    1.26 +              error("Error while sending error response (" .. status .. " / " .. text .. "): " .. errmsg)
    1.27              else
    1.28 -              error("Error while sending error response (" .. status .. "): " .. errmsg2)
    1.29 +              error("Error while sending error response (" .. status .. "): " .. errmsg)
    1.30              end
    1.31            end
    1.32 -        elseif state ~= "faulty" then
    1.33 -          state = "faulty"
    1.34 -          assert_close(socket:reset())
    1.35          end
    1.36          if throw_error then
    1.37 +          local errmsg = "Error while reading request from client. Error response: " .. status
    1.38 +          if text then
    1.39 +            errmsg = errmsg .. " (" .. text .. ")"
    1.40 +          end
    1.41            error(errmsg)
    1.42          else
    1.43            return survive
    1.44 @@ -478,18 +475,18 @@
    1.45          return data
    1.46        end
    1.47        -- reads a number of bytes from the socket,
    1.48 -      -- optionally feeding these bytes chunk-wise
    1.49 -      -- into a callback function:
    1.50 +      -- optionally feeding these bytes chunk-wise into
    1.51 +      -- the "process_body_chunk" callback function:
    1.52        local function read_body_bytes(remaining)
    1.53          while remaining > 0 do
    1.54 -          local limit
    1.55 +          local chunklen
    1.56            if remaining > input_chunk_size then
    1.57 -            limit = input_chunk_size
    1.58 +            chunklen = input_chunk_size
    1.59            else
    1.60 -            limit = remaining
    1.61 +            chunklen = remaining
    1.62            end
    1.63 -          local chunk = read(limit)
    1.64 -          remaining = remaining - limit
    1.65 +          local chunk = read(chunklen)
    1.66 +          remaining = remaining - chunklen
    1.67            if process_body_chunk then
    1.68              process_body_chunk(chunk)
    1.69            end

Impressum / About Us