From 0bbcab4e51651d749abe6bf55bb6fb1f5d046243 Mon Sep 17 00:00:00 2001 From: Anton Shestakov Date: Fri, 12 Aug 2016 13:29:27 +0800 Subject: ejabberdsql2prosody: remove unused function pushback() [luacheck] The same function seems to exist in tools/erlparse.lua, also unused. --- tools/ejabberdsql2prosody.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua index 69c8cfe8..a9d624aa 100644 --- a/tools/ejabberdsql2prosody.lua +++ b/tools/ejabberdsql2prosody.lua @@ -42,10 +42,6 @@ local function read(expected) if expected and ch ~= expected then error("expected: "..expected.."; got: "..(ch or "nil").." on line "..line); end return ch; end -local function pushback(ch) - if last then error(); end - last = ch; -end local function peek() if not last then last = read(); end return last; -- cgit v1.2.3 From b6969ffbebb60897a1ed8246d8ffa28fb3930d2c Mon Sep 17 00:00:00 2001 From: Anton Shestakov Date: Fri, 12 Aug 2016 13:31:16 +0800 Subject: ejabberdsql2prosody: remove unused one-letter loop variables [luacheck] --- tools/ejabberdsql2prosody.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua index a9d624aa..be42f256 100644 --- a/tools/ejabberdsql2prosody.lua +++ b/tools/ejabberdsql2prosody.lua @@ -215,7 +215,7 @@ for name, data in pairs(t) do end --print(serialize(t)); -for i, row in ipairs(t["users"] or NULL) do +for _, row in ipairs(t["users"] or NULL) do local node, password = row.username, row.password; local ret, err = dm.store(node, host, "accounts", {password = password}); print("["..(err or "success").."] accounts: "..node.."@"..host); @@ -254,7 +254,7 @@ function offline_msg(node, host, t, stanza) local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); end -for i, row in ipairs(t["rosterusers"] or NULL) do +for _, row in ipairs(t["rosterusers"] or NULL) do local node, contact = row.username, row.jid; local name = row.nick; if name == "" then name = nil; end @@ -283,10 +283,10 @@ for i, row in ipairs(t["rosterusers"] or NULL) do local item = {name = name, ask = ask, subscription = subscription, groups = {}}; roster(node, host, contact, item); end -for i, row in ipairs(t["rostergroups"] or NULL) do +for _, row in ipairs(t["rostergroups"] or NULL) do roster_group(row.username, host, row.jid, row.grp); end -for i, row in ipairs(t["vcard"] or NULL) do +for _, row in ipairs(t["vcard"] or NULL) do local stanza, err = parse_xml(row.vcard); if stanza then local ret, err = dm.store(row.username, host, "vcard", st.preserialize(stanza)); @@ -295,7 +295,7 @@ for i, row in ipairs(t["vcard"] or NULL) do print("[error] vCard XML parse failed: "..row.username.."@"..host); end end -for i, row in ipairs(t["private_storage"] or NULL) do +for _, row in ipairs(t["private_storage"] or NULL) do local stanza, err = parse_xml(row.data); if stanza then private_storage(row.username, host, row.namespace, stanza); @@ -309,7 +309,7 @@ local date_parse = function(s) local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)"); return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset}); end -for i, row in ipairs(t["spool"] or NULL) do +for _, row in ipairs(t["spool"] or NULL) do local stanza, err = parse_xml(row.xml); if stanza then local last_child = stanza.tags[#stanza.tags]; -- cgit v1.2.3 From 41c7847806b0b65b6b2161ff27badf396a9cc32a Mon Sep 17 00:00:00 2001 From: Anton Shestakov Date: Fri, 12 Aug 2016 13:44:47 +0800 Subject: ejabberdsql2prosody: rename variable 'host' to prevent shadowing upvalue [luacheck] Functions roster(), roster_pending(), roster_group(), private_storage() and offline_msg() have argument named "host", which used to shadow upvalue of this variable before this change. Instead of renaming this argument, let's rename the variable to match what the script says in usage: Usage: ejabberdsql2prosody.lua filename.txt hostname --- tools/ejabberdsql2prosody.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua index be42f256..f65ada6f 100644 --- a/tools/ejabberdsql2prosody.lua +++ b/tools/ejabberdsql2prosody.lua @@ -172,9 +172,9 @@ return readFile(filename); ------ end -local arg, host = ...; +local arg, hostname = ...; local help = "/? -? ? /h -h /help -help --help"; -if not(arg and host) or help:find(arg, 1, true) then +if not(arg and hostname) or help:find(arg, 1, true) then print([[ejabberd SQL DB dump importer for Prosody Usage: ejabberdsql2prosody.lua filename.txt hostname @@ -217,8 +217,8 @@ end for _, row in ipairs(t["users"] or NULL) do local node, password = row.username, row.password; - local ret, err = dm.store(node, host, "accounts", {password = password}); - print("["..(err or "success").."] accounts: "..node.."@"..host); + local ret, err = dm.store(node, hostname, "accounts", {password = password}); + print("["..(err or "success").."] accounts: "..node.."@"..hostname); end function roster(node, host, jid, item) @@ -274,33 +274,33 @@ for _, row in ipairs(t["rosterusers"] or NULL) do elseif ask == "O" then ask = "subscribe"; elseif ask == "I" then - roster_pending(node, host, contact); + roster_pending(node, hostname, contact); ask = nil; elseif ask == "B" then - roster_pending(node, host, contact); + roster_pending(node, hostname, contact); ask = "subscribe"; else error("Unknown ask type: "..ask); end local item = {name = name, ask = ask, subscription = subscription, groups = {}}; - roster(node, host, contact, item); + roster(node, hostname, contact, item); end for _, row in ipairs(t["rostergroups"] or NULL) do - roster_group(row.username, host, row.jid, row.grp); + roster_group(row.username, hostname, row.jid, row.grp); end for _, row in ipairs(t["vcard"] or NULL) do local stanza, err = parse_xml(row.vcard); if stanza then - local ret, err = dm.store(row.username, host, "vcard", st.preserialize(stanza)); - print("["..(err or "success").."] vCard: "..row.username.."@"..host); + local ret, err = dm.store(row.username, hostname, "vcard", st.preserialize(stanza)); + print("["..(err or "success").."] vCard: "..row.username.."@"..hostname); else - print("[error] vCard XML parse failed: "..row.username.."@"..host); + print("[error] vCard XML parse failed: "..row.username.."@"..hostname); end end for _, row in ipairs(t["private_storage"] or NULL) do local stanza, err = parse_xml(row.data); if stanza then - private_storage(row.username, host, row.namespace, stanza); + private_storage(row.username, hostname, row.namespace, stanza); else - print("[error] Private XML parse failed: "..row.username.."@"..host); + print("[error] Private XML parse failed: "..row.username.."@"..hostname); end end table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case @@ -317,8 +317,8 @@ for _, row in ipairs(t["spool"] or NULL) do if last_child.name ~= "x" and last_child.attr.xmlns ~= "jabber:x:delay" then error("Last child of offline message is not a timestamp"); end stanza[#stanza], stanza.tags[#stanza.tags] = nil, nil; local t = date_parse(last_child.attr.stamp); - offline_msg(row.username, host, t, stanza); + offline_msg(row.username, hostname, t, stanza); else - print("[error] Offline message XML parsing failed: "..row.username.."@"..host); + print("[error] Offline message XML parsing failed: "..row.username.."@"..hostname); end end -- cgit v1.2.3 From 9129ea5b4c556f94436c50c4ff8711c6c78ee5c5 Mon Sep 17 00:00:00 2001 From: Anton Shestakov Date: Fri, 12 Aug 2016 13:51:38 +0800 Subject: ejabberdsql2prosody: rename variable 't' to prevent shadowing upvalues [luacheck] Let's make the result of parseFile() have a more descriptive name. --- tools/ejabberdsql2prosody.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/ejabberdsql2prosody.lua b/tools/ejabberdsql2prosody.lua index f65ada6f..d0ab71cf 100644 --- a/tools/ejabberdsql2prosody.lua +++ b/tools/ejabberdsql2prosody.lua @@ -197,8 +197,8 @@ local map = { --["vcard_search"] = {}; } local NULL = {}; -local t = parseFile(arg); -for name, data in pairs(t) do +local parsed = parseFile(arg); +for name, data in pairs(parsed) do local m = map[name]; if m then if #data > 0 and #data[1] ~= #m then @@ -215,7 +215,7 @@ for name, data in pairs(t) do end --print(serialize(t)); -for _, row in ipairs(t["users"] or NULL) do +for _, row in ipairs(parsed["users"] or NULL) do local node, password = row.username, row.password; local ret, err = dm.store(node, hostname, "accounts", {password = password}); print("["..(err or "success").."] accounts: "..node.."@"..hostname); @@ -254,7 +254,7 @@ function offline_msg(node, host, t, stanza) local ret, err = dm.list_append(node, host, "offline", st.preserialize(stanza)); print("["..(err or "success").."] offline: " ..node.."@"..host.." - "..os.date("!%Y-%m-%dT%H:%M:%SZ", t)); end -for _, row in ipairs(t["rosterusers"] or NULL) do +for _, row in ipairs(parsed["rosterusers"] or NULL) do local node, contact = row.username, row.jid; local name = row.nick; if name == "" then name = nil; end @@ -283,10 +283,10 @@ for _, row in ipairs(t["rosterusers"] or NULL) do local item = {name = name, ask = ask, subscription = subscription, groups = {}}; roster(node, hostname, contact, item); end -for _, row in ipairs(t["rostergroups"] or NULL) do +for _, row in ipairs(parsed["rostergroups"] or NULL) do roster_group(row.username, hostname, row.jid, row.grp); end -for _, row in ipairs(t["vcard"] or NULL) do +for _, row in ipairs(parsed["vcard"] or NULL) do local stanza, err = parse_xml(row.vcard); if stanza then local ret, err = dm.store(row.username, hostname, "vcard", st.preserialize(stanza)); @@ -295,7 +295,7 @@ for _, row in ipairs(t["vcard"] or NULL) do print("[error] vCard XML parse failed: "..row.username.."@"..hostname); end end -for _, row in ipairs(t["private_storage"] or NULL) do +for _, row in ipairs(parsed["private_storage"] or NULL) do local stanza, err = parse_xml(row.data); if stanza then private_storage(row.username, hostname, row.namespace, stanza); @@ -303,13 +303,13 @@ for _, row in ipairs(t["private_storage"] or NULL) do print("[error] Private XML parse failed: "..row.username.."@"..hostname); end end -table.sort(t["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case +table.sort(parsed["spool"] or NULL, function(a,b) return a.seq < b.seq; end); -- sort by sequence number, just in case local time_offset = os.difftime(os.time(os.date("!*t")), os.time(os.date("*t"))) -- to deal with timezones local date_parse = function(s) local year, month, day, hour, min, sec = s:match("(....)-?(..)-?(..)T(..):(..):(..)"); return os.time({year=year, month=month, day=day, hour=hour, min=min, sec=sec-time_offset}); end -for _, row in ipairs(t["spool"] or NULL) do +for _, row in ipairs(parsed["spool"] or NULL) do local stanza, err = parse_xml(row.xml); if stanza then local last_child = stanza.tags[#stanza.tags]; -- cgit v1.2.3 From 0468aa76f1e3be9af2cf75392423fec2b0d2db79 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 13 Aug 2016 15:09:43 +0200 Subject: net.http.parser: Remove unused argument [luacheck] --- 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 6d7187da..70df6513 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -35,7 +35,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) local have_body; local error; return { - feed = function(self, data) + feed = function(_, data) if error then return nil, "parse has failed"; end if not data then -- EOF if state and client and not len then -- reading client body until EOF -- cgit v1.2.3 From 3550142f0bfe96a5ef90f07dafcdf6dec3000e21 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 13 Aug 2016 15:42:57 +0200 Subject: mod_register: Fix inverted throttle check (fixes #724) --- plugins/mod_register.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua index fda717f7..df833cad 100644 --- a/plugins/mod_register.lua +++ b/plugins/mod_register.lua @@ -226,7 +226,7 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event) session.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not allowed to register an account.")); return true; elseif min_seconds_between_registrations and not whitelisted_ips[session.ip] then - if check_throttle(session.ip) then + if not check_throttle(session.ip) then session.send(st.error_reply(stanza, "wait", "not-acceptable")); return true; end -- cgit v1.2.3 From 8c797be6c44961cdd5a3f712ae421832cc4c22f0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 13 Aug 2016 16:10:17 +0200 Subject: net.http.codes: Remove used argument --- net/http/codes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/http/codes.lua b/net/http/codes.lua index bc31c7dd..1801c6b3 100644 --- a/net/http/codes.lua +++ b/net/http/codes.lua @@ -70,4 +70,4 @@ local response_codes = { }; for k,v in pairs(response_codes) do response_codes[k] = k.." "..v; end -return setmetatable(response_codes, { __index = function(t, k) return k.." Unassigned"; end }) +return setmetatable(response_codes, { __index = function(_, k) return k.." Unassigned"; end }) -- cgit v1.2.3 From 4c89d041878972b771a7a593f9358c6bdb17d6c7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 13 Aug 2016 16:11:30 +0200 Subject: net.http.codes: Add HTTP status code 451 Unavailable For Legal Reasons from RFC 7725 --- net/http/codes.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/net/http/codes.lua b/net/http/codes.lua index 1801c6b3..1090e545 100644 --- a/net/http/codes.lua +++ b/net/http/codes.lua @@ -55,6 +55,7 @@ local response_codes = { [428] = "Precondition Required"; [429] = "Too Many Requests"; [431] = "Request Header Fields Too Large"; + [451] = "Unavailable For Legal Reasons"; [500] = "Internal Server Error"; [501] = "Not Implemented"; -- cgit v1.2.3 From 47ed467f4f7dbab0615054413e18d32846c91740 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 13 Aug 2016 20:19:08 +0200 Subject: net.http.parser: Buffer into a table to reduce GC pressure, collapse to string when needed (fixes #603) --- net/http/parser.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/net/http/parser.lua b/net/http/parser.lua index 6d7187da..af43e7a0 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -1,5 +1,6 @@ local tonumber = tonumber; local assert = assert; +local t_insert, t_concat = table.insert, table.concat; local url_parse = require "socket.url".parse; local urldecode = require "util.http".urldecode; @@ -27,7 +28,7 @@ local httpstream = {}; function httpstream.new(success_cb, error_cb, parser_type, options_cb) local client = true; if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end - local buf = ""; + local buf, buflen, buftable = {}, 0, true; local chunked, chunk_size, chunk_start; local state = nil; local packet; @@ -38,6 +39,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) feed = function(self, data) if error then return nil, "parse has failed"; end if not data then -- EOF + if buftable then buf, buftable = t_concat(buf), false; end if state and client and not len then -- reading client body until EOF packet.body = buf; success_cb(packet); @@ -46,9 +48,16 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) end return; end - buf = buf..data; - while #buf > 0 do + if buftable then + t_insert(buf, data); + else + buf = { buf, data }; + buftable = true; + end + buflen = buflen + #data; + while buflen > 0 do if state == nil then -- read request + if buftable then buf, buftable = t_concat(buf), false; end local index = buf:find("\r\n\r\n", nil, true); if not index then return; end -- not enough data local method, path, httpversion, status_code, reason_phrase; @@ -115,11 +124,13 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) }; end buf = buf:sub(index + 4); + buflen = #buf; state = true; end if state then -- read body if client then if chunked then + if buftable then buf, buftable = t_concat(buf), false; end if not buf:find("\r\n", nil, true) then return; end -- not enough data @@ -132,25 +143,29 @@ 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 buflen - 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; else -- Partial chunk remaining break; end - elseif len and #buf >= len then + elseif len and buflen >= len then + if buftable then buf, buftable = t_concat(buf), false; end if packet.code == 101 then - packet.body, buf = buf, ""; + packet.body, buf, buflen, buftable = buf, {}, 0, true; else packet.body, buf = buf:sub(1, len), buf:sub(len + 1); + buflen = #buf; end state = nil; success_cb(packet); else break; end - elseif #buf >= len then + elseif buflen >= len then + if buftable then buf, buftable = t_concat(buf), false; end packet.body, buf = buf:sub(1, len), buf:sub(len + 1); + buflen = #buf; state = nil; success_cb(packet); else break; -- cgit v1.2.3 From b50763dcf67719fa26a5cd1bcfdde4e416363e74 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:47:58 +0200 Subject: net.http.parser: Add a limit on content length, default to 10M --- net/http/parser.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/http/parser.lua b/net/http/parser.lua index af43e7a0..0f764d12 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -29,6 +29,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) local client = true; if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end local buf, buflen, buftable = {}, 0, true; + local bodylimit = 10*1024*1024; local chunked, chunk_size, chunk_start; local state = nil; local packet; @@ -88,6 +89,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) if not first_line then error = true; return error_cb("invalid-status-line"); end chunked = have_body and headers["transfer-encoding"] == "chunked"; len = tonumber(headers["content-length"]); -- TODO check for invalid len + if len and len > bodylimit then error = true; return error_cb("content-length-limit-exceeded"); end if client then -- FIXME handle '100 Continue' response (by skipping it) if not have_body then len = 0; end -- cgit v1.2.3 From bdae29d75431867aaf584ca88787233682426a9a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:48:42 +0200 Subject: net.http.parser: Add a limit on maximum buffer size, default to 20M --- net/http/parser.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/http/parser.lua b/net/http/parser.lua index 0f764d12..e3a2554f 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -30,6 +30,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end local buf, buflen, buftable = {}, 0, true; local bodylimit = 10*1024*1024; + local buflimit = bodylimit * 2; local chunked, chunk_size, chunk_start; local state = nil; local packet; @@ -56,6 +57,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) buftable = true; end buflen = buflen + #data; + if buflen > buflimit then error = true; return error_cb("max-buffer-size-exceeded"); end while buflen > 0 do if state == nil then -- read request if buftable then buf, buftable = t_concat(buf), false; end -- cgit v1.2.3 From 4fe3ec81e1ca2f13fd945e9afcaf5af2733ade73 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:50:06 +0200 Subject: net.http.parser: Allow limits to be configurable via options callback --- net/http/parser.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/http/parser.lua b/net/http/parser.lua index e3a2554f..1e698728 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -29,8 +29,8 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) local client = true; if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end local buf, buflen, buftable = {}, 0, true; - local bodylimit = 10*1024*1024; - local buflimit = bodylimit * 2; + local bodylimit = tonumber(options_cb and options_cb().body_size_limit) or 10*1024*1024; + local buflimit = tonumber(options_cb and options_cb().buffer_size_limit) or bodylimit * 2; local chunked, chunk_size, chunk_start; local state = nil; local packet; -- cgit v1.2.3 From 47fe58f5ca703f0c8f6378a7f8a46d7565bcef90 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:50:39 +0200 Subject: net.http.server: Expose way to set http server options --- net/http/server.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/http/server.lua b/net/http/server.lua index f091595c..32cda8aa 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -19,6 +19,7 @@ local sessions = {}; local listener = {}; local hosts = {}; local default_host; +local options = {}; local function is_wildcard_event(event) return event:sub(-2, -1) == "/*"; @@ -130,7 +131,10 @@ function listener.onconnect(conn) sessions[conn] = nil; conn:close(); end - sessions[conn] = parser_new(success_cb, error_cb); + local function options_cb() + return options; + end + sessions[conn] = parser_new(success_cb, error_cb, "server", options_cb); end function listener.ondisconnect(conn) @@ -300,6 +304,9 @@ end function _M.fire_event(event, ...) return events.fire_event(event, ...); end +function _M.set_option(name, value) + options[name] = value; +end _M.listener = listener; _M.codes = codes; -- cgit v1.2.3 From 1686ef5d53d3d84d35ebebab89b8d1b22dcf021e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:51:11 +0200 Subject: mod_http: Allow configuring http parser size limits --- plugins/mod_http.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua index 9b574bc8..03b23480 100644 --- a/plugins/mod_http.lua +++ b/plugins/mod_http.lua @@ -18,6 +18,9 @@ local server = require "net.http.server"; server.set_default_host(module:get_option_string("http_default_host")); +server.set_option("body_size_limit", module:get_option_number("http_max_content_size")); +server.set_option("buffer_size_limit", module:get_option_number("http_max_buffer_size")); + local function normalize_path(path) if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end if path:sub(1,1) ~= "/" then path = "/"..path; end -- cgit v1.2.3 From f30f5f62189373fe8a2081d1117fbc2977331f26 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 15:21:30 +0200 Subject: net.http.server: Add luacheck annotations --- net/http/server.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/http/server.lua b/net/http/server.lua index 93bbffb4..8aa28f5c 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -32,7 +32,7 @@ local function is_wildcard_match(wildcard_event, event) end local _handlers = events._handlers; -local recent_wildcard_events = cache.new(10000, function (key, value) +local recent_wildcard_events = cache.new(10000, function (key, value) -- luacheck: ignore 212/value rawset(_handlers, key, nil); end); @@ -174,7 +174,7 @@ local headerfix = setmetatable({}, { end }); -function _M.hijack_response(response, listener) +function _M.hijack_response(response, listener) -- luacheck: ignore error("TODO"); end function handle_request(conn, request, finish_cb) -- cgit v1.2.3