moonbridge

changeset 176:b2d024220782

Renamed remaining_header_size_limit and remaining_body_size_limit to local "limit" variables
author jbe
date Thu Jun 18 22:16:08 2015 +0200 (2015-06-18)
parents 4cf337821a52
children b03857995d57
files moonbridge_http.lua
line diff
     1.1 --- a/moonbridge_http.lua	Thu Jun 18 04:09:21 2015 +0200
     1.2 +++ b/moonbridge_http.lua	Thu Jun 18 22:16:08 2015 +0200
     1.3 @@ -206,8 +206,9 @@
     1.4    return function(socket)
     1.5      local socket_set = {[socket] = true}  -- used for poll function
     1.6      local survive = true  -- set to false if process shall be terminated later
     1.7 -    local consume  -- function that reads some input if possible
     1.8 -    -- function that drains some input if possible:
     1.9 +    local consume  -- can be set to function that reads some input if possible
    1.10 +    -- function that may be used as "consume" function
    1.11 +    -- and which drains some input if possible:
    1.12      local function drain()
    1.13        local bytes, status = socket:drain_nb(input_chunk_size)
    1.14        if not bytes or status == "eof" then
    1.15 @@ -232,9 +233,6 @@
    1.16      end
    1.17      -- handle requests in a loop:
    1.18      repeat
    1.19 -      -- copy limits:
    1.20 -      local remaining_header_size_limit = header_size_limit
    1.21 -      local remaining_body_size_limit = body_size_limit
    1.22        -- table for caching nil values:
    1.23        local headers_value_nil = {}
    1.24        -- create a new request object with metatable:
    1.25 @@ -489,8 +487,9 @@
    1.26        -- coroutine for request body processing:
    1.27        local function read_body()
    1.28          if request.headers_flags["Transfer-Encoding"]["chunked"] then
    1.29 +          local limit = body_size_limit
    1.30            while true do
    1.31 -            local line = read(32 + remaining_body_size_limit, "\n")
    1.32 +            local line = read(32 + limit, "\n")
    1.33              local zeros, lenstr = string.match(line, "^(0*)([1-9A-Fa-f]+[0-9A-Fa-f]*)\r?\n$")
    1.34              local chunkext
    1.35              if lenstr then
    1.36 @@ -502,8 +501,8 @@
    1.37                request_error(true, "400 Bad Request", "Encoding error while reading chunk of request body")
    1.38              end
    1.39              local len = tonumber("0x" .. lenstr)
    1.40 -            remaining_body_size_limit = remaining_body_size_limit - (#zeros + #chunkext + len)
    1.41 -            if remaining_body_size_limit < 0 then
    1.42 +            limit = limit - (#zeros + #chunkext + len)
    1.43 +            if limit < 0 then
    1.44                request_error(true, "413 Request Entity Too Large", "Request body size limit exceeded")
    1.45              end
    1.46              if len == 0 then break end
    1.47 @@ -514,10 +513,10 @@
    1.48              end
    1.49            end
    1.50            while true do
    1.51 -            local line = read(2 + remaining_body_size_limit, "\n")
    1.52 +            local line = read(2 + limit, "\n")
    1.53              if line == "\r\n" or line == "\n" then break end
    1.54 -            remaining_body_size_limit = remaining_body_size_limit - #line
    1.55 -            if remaining_body_size_limit < 0 then
    1.56 +            limit = limit - #line
    1.57 +            if limit < 0 then
    1.58                request_error(true, "413 Request Entity Too Large", "Request body size limit exceeded while reading trailer section of chunked request body")
    1.59              end
    1.60            end
    1.61 @@ -966,13 +965,15 @@
    1.62        end
    1.63        -- coroutine for reading headers:
    1.64        local function read_headers()
    1.65 +        -- initialize limit:
    1.66 +        local limit = header_size_limit
    1.67          -- read and parse request line:
    1.68 -        local line = read_eof(remaining_header_size_limit, "\n")
    1.69 +        local line = read_eof(limit, "\n")
    1.70          if not line then
    1.71            return false, survive
    1.72          end
    1.73 -        remaining_header_size_limit = remaining_header_size_limit - #line
    1.74 -        if remaining_header_size_limit == 0 then
    1.75 +        limit = limit - #line
    1.76 +        if limit == 0 then
    1.77            return false, request_error(false, "414 Request-URI Too Long")
    1.78          end
    1.79          local target, proto
    1.80 @@ -985,12 +986,12 @@
    1.81          end
    1.82          -- read and parse headers:
    1.83          while true do
    1.84 -          local line = read(remaining_header_size_limit, "\n");
    1.85 -          remaining_header_size_limit = remaining_header_size_limit - #line
    1.86 +          local line = read(limit, "\n");
    1.87 +          limit = limit - #line
    1.88            if line == "\r\n" or line == "\n" then
    1.89              break
    1.90            end
    1.91 -          if remaining_header_size_limit == 0 then
    1.92 +          if limit == 0 then
    1.93              return false, request_error(false, "431 Request Header Fields Too Large")
    1.94            end
    1.95            local key, value = string.match(line, "^([^ \t\r]+):[ \t]*(.-)[ \t]*\r?\n$")
    1.96 @@ -1043,7 +1044,7 @@
    1.97                return request_error(false, "400 Bad Request", "Content-Length header(s) invalid")
    1.98              end
    1.99            end
   1.100 -          if request_body_content_length > remaining_body_size_limit then
   1.101 +          if request_body_content_length > body_size_limit then
   1.102              return request_error(false, "413 Request Entity Too Large", "Announced request body size is too big")
   1.103            end
   1.104          end

Impressum / About Us