Skip to content

Commit

Permalink
Update waf.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
loveshell committed Dec 12, 2013
1 parent 047e027 commit ed6b345
Showing 1 changed file with 33 additions and 24 deletions.
57 changes: 33 additions & 24 deletions waf.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local upload = require "upload"
local content_length=tonumber(ngx.req.get_headers()['content-length'])
local content_length=tonumber(ngx.req.get_headers()['content-length'])
local method=ngx.req.get_method()
if whiteip() then
elseif blockip() then
Expand All @@ -15,30 +14,40 @@ elseif args() then
elseif cookie() then
elseif PostCheck then
if method=="POST" then
local boundary = get_boundary()
if boundary then
local form = upload:new(500)
if not form then
return
local boundary = get_boundary()
if boundary then
local len = string.len
local sock, err = ngx.req.socket()
if not sock then
return
end
form:set_timeout(1000) -- 1 sec
while true do
local typ, res, err = form:read()
if not typ then
return
end
if typ=="body" then
body(res)
end

if typ == "eof" then
break
end
ngx.req.init_body(128 * 1024)
sock:settimeout(0)
local content_length = nil
content_length=tonumber(ngx.req.get_headers()['content-length'])
local chunk_size = 4096
if content_length < chunk_size then
chunk_size = content_length
end
local size = 0
while size < content_length do
local data, err, partial = sock:receive(chunk_size)
data = data or partial
if not data then
return
end
ngx.req.append_body(data)
size = size + len(data)
local less = content_length - size
if less < chunk_size then
chunk_size = less
end
end

-- local typ, res, err = form:read()
-- body(res)
else
ngx.req.finish_body()
if body(data) then
return true
end
else
ngx.req.read_body()
local args = ngx.req.get_post_args()
if not args then
Expand Down

0 comments on commit ed6b345

Please sign in to comment.