Skip to content

Commit ed6b345

Browse files
committed
Update waf.lua
1 parent 047e027 commit ed6b345

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

waf.lua

+33-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
local upload = require "upload"
2-
local content_length=tonumber(ngx.req.get_headers()['content-length'])
1+
local content_length=tonumber(ngx.req.get_headers()['content-length'])
32
local method=ngx.req.get_method()
43
if whiteip() then
54
elseif blockip() then
@@ -15,30 +14,40 @@ elseif args() then
1514
elseif cookie() then
1615
elseif PostCheck then
1716
if method=="POST" then
18-
local boundary = get_boundary()
19-
if boundary then
20-
local form = upload:new(500)
21-
if not form then
22-
return
17+
local boundary = get_boundary()
18+
if boundary then
19+
local len = string.len
20+
local sock, err = ngx.req.socket()
21+
if not sock then
22+
return
2323
end
24-
form:set_timeout(1000) -- 1 sec
25-
while true do
26-
local typ, res, err = form:read()
27-
if not typ then
28-
return
29-
end
30-
if typ=="body" then
31-
body(res)
32-
end
33-
34-
if typ == "eof" then
35-
break
36-
end
24+
ngx.req.init_body(128 * 1024)
25+
sock:settimeout(0)
26+
local content_length = nil
27+
content_length=tonumber(ngx.req.get_headers()['content-length'])
28+
local chunk_size = 4096
29+
if content_length < chunk_size then
30+
chunk_size = content_length
31+
end
32+
local size = 0
33+
while size < content_length do
34+
local data, err, partial = sock:receive(chunk_size)
35+
data = data or partial
36+
if not data then
37+
return
38+
end
39+
ngx.req.append_body(data)
40+
size = size + len(data)
41+
local less = content_length - size
42+
if less < chunk_size then
43+
chunk_size = less
44+
end
3745
end
38-
39-
-- local typ, res, err = form:read()
40-
-- body(res)
41-
else
46+
ngx.req.finish_body()
47+
if body(data) then
48+
return true
49+
end
50+
else
4251
ngx.req.read_body()
4352
local args = ngx.req.get_post_args()
4453
if not args then

0 commit comments

Comments
 (0)