Software /
code /
prosody
Comparison
net/http/parser.lua @ 7577:3dc52f1778db
net.http.parser: Add a limit on maximum buffer size, default to 20M
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Aug 2016 14:48:42 +0200 |
parent | 7576:d3646443a02e |
child | 7578:65bf55fdf971 |
comparison
equal
deleted
inserted
replaced
7576:d3646443a02e | 7577:3dc52f1778db |
---|---|
28 function httpstream.new(success_cb, error_cb, parser_type, options_cb) | 28 function httpstream.new(success_cb, error_cb, parser_type, options_cb) |
29 local client = true; | 29 local client = true; |
30 if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end | 30 if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end |
31 local buf, buflen, buftable = {}, 0, true; | 31 local buf, buflen, buftable = {}, 0, true; |
32 local bodylimit = 10*1024*1024; | 32 local bodylimit = 10*1024*1024; |
33 local buflimit = bodylimit * 2; | |
33 local chunked, chunk_size, chunk_start; | 34 local chunked, chunk_size, chunk_start; |
34 local state = nil; | 35 local state = nil; |
35 local packet; | 36 local packet; |
36 local len; | 37 local len; |
37 local have_body; | 38 local have_body; |
54 else | 55 else |
55 buf = { buf, data }; | 56 buf = { buf, data }; |
56 buftable = true; | 57 buftable = true; |
57 end | 58 end |
58 buflen = buflen + #data; | 59 buflen = buflen + #data; |
60 if buflen > buflimit then error = true; return error_cb("max-buffer-size-exceeded"); end | |
59 while buflen > 0 do | 61 while buflen > 0 do |
60 if state == nil then -- read request | 62 if state == nil then -- read request |
61 if buftable then buf, buftable = t_concat(buf), false; end | 63 if buftable then buf, buftable = t_concat(buf), false; end |
62 local index = buf:find("\r\n\r\n", nil, true); | 64 local index = buf:find("\r\n\r\n", nil, true); |
63 if not index then return; end -- not enough data | 65 if not index then return; end -- not enough data |