moonbridge

changeset 158:8ab33bfb47e7

Minimal changes to HTTP module to support interface of new :read(...) method
author jbe
date Wed May 27 02:55:48 2015 +0200 (2015-05-27)
parents 08cf8e1865e9
children d5b8295d035e
files moonbridge_http.lua
line diff
     1.1 --- a/moonbridge_http.lua	Tue May 19 23:15:22 2015 +0200
     1.2 +++ b/moonbridge_http.lua	Wed May 27 02:55:48 2015 +0200
     1.3 @@ -182,17 +182,17 @@
     1.4    local output_chunk_size = options.minimum_output_chunk_size or options.chunk_size or 1024
     1.5    local request_idle_timeout, request_header_timeout, response_timeout
     1.6    if options.request_idle_timeout ~= nil then
     1.7 -    request_idle_timeout = options.request_idle_timeout or 0
     1.8 +    request_idle_timeout = options.request_idle_timeout
     1.9    else
    1.10      request_idle_timeout = 330
    1.11    end
    1.12    if options.request_header_timeout ~= nil then
    1.13 -    request_header_timeout = options.request_header_timeout or 0
    1.14 +    request_header_timeout = options.request_header_timeout
    1.15    else
    1.16      request_header_timeout = 30
    1.17    end
    1.18    if options.timeout ~= nil then
    1.19 -    response_timeout = options.timeout or 0
    1.20 +    response_timeout = options.timeout
    1.21    else
    1.22      response_timeout = 1800
    1.23    end
    1.24 @@ -840,7 +840,7 @@
    1.25              while true do
    1.26                local line = socket:read(32 + remaining_body_size_limit, "\n")
    1.27                if not line then
    1.28 -                request_error(true, "400 Bad Request", "Unexpected EOF while reading next chunk of request body")
    1.29 +                request_error(true, "400 Bad Request", "Read error while reading next chunk of request body")
    1.30                end
    1.31                local zeros, lenstr = string.match(line, "^(0*)([1-9A-Fa-f]+[0-9A-Fa-f]*)\r?\n$")
    1.32                local chunkext
    1.33 @@ -860,12 +860,18 @@
    1.34                if len == 0 then break end
    1.35                read_body_bytes(len, callback)
    1.36                local term = socket:read(2, "\n")
    1.37 +              if not term then
    1.38 +                request_error(true, "400 Bad Request", "Read error while reading chunk of request body")
    1.39 +              end
    1.40                if term ~= "\r\n" and term ~= "\n" then
    1.41                  request_error(true, "400 Bad Request", "Encoding error while reading chunk of request body")
    1.42                end
    1.43              end
    1.44              while true do
    1.45                local line = socket:read(2 + remaining_body_size_limit, "\n")
    1.46 +              if not line then
    1.47 +                request_error(true, "400 Bad Request", "Read error while reading chunk of request body")
    1.48 +              end
    1.49                if line == "\r\n" or line == "\n" then break end
    1.50                remaining_body_size_limit = remaining_body_size_limit - #line
    1.51                if remaining_body_size_limit < 0 then
    1.52 @@ -900,14 +906,17 @@
    1.53          end
    1.54        })
    1.55        -- wait for input:
    1.56 -      if not moonbridge_io.poll({[socket] = true}, nil, request_idle_timeout) then
    1.57 +      if not moonbridge_io.poll({[socket] = true}, nil, request_idle_timeout or nil) then
    1.58          return request_error(false, "408 Request Timeout")
    1.59        end
    1.60        -- set timeout for request header processing:
    1.61 -      timeout(request_header_timeout)
    1.62 +      timeout(request_header_timeout or 0)
    1.63        -- read and parse request line:
    1.64        local line = socket:read(remaining_header_size_limit, "\n")
    1.65 -      if not line then return survive end
    1.66 +      if not line then
    1.67 +        return request_error(false, "400 Bad Request", "Read error while reading request line")
    1.68 +      end
    1.69 +      if line == "" then return survive end
    1.70        remaining_header_size_limit = remaining_header_size_limit - #line
    1.71        if remaining_header_size_limit == 0 then
    1.72          return request_error(false, "414 Request-URI Too Long")
    1.73 @@ -922,11 +931,11 @@
    1.74        end
    1.75        -- read and parse headers:
    1.76        while true do
    1.77 -        local line = socket:read(remaining_header_size_limit, "\n");
    1.78 -        remaining_header_size_limit = remaining_header_size_limit - #line
    1.79 +        local line = socket:read(remaining_header_size_limit, "\n")
    1.80          if not line then
    1.81 -          return request_error(false, "400 Bad Request")
    1.82 +          return request_error(false, "400 Bad Request", "Read error while reading header line")
    1.83          end
    1.84 +        remaining_header_size_limit = remaining_header_size_limit - #line
    1.85          if line == "\r\n" or line == "\n" then
    1.86            break
    1.87          end

Impressum / About Us