Browse Source

Update waf.lua

pull/23/head
loveshell 11 years ago
parent
commit
ed6b345db3
  1. 57
      waf.lua

57
waf.lua

@ -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() local method=ngx.req.get_method()
if whiteip() then if whiteip() then
elseif blockip() then elseif blockip() then
@ -15,30 +14,40 @@ elseif args() then
elseif cookie() then elseif cookie() then
elseif PostCheck then elseif PostCheck then
if method=="POST" then if method=="POST" then
local boundary = get_boundary() local boundary = get_boundary()
if boundary then if boundary then
local form = upload:new(500) local len = string.len
if not form then local sock, err = ngx.req.socket()
return if not sock then
return
end end
form:set_timeout(1000) -- 1 sec ngx.req.init_body(128 * 1024)
while true do sock:settimeout(0)
local typ, res, err = form:read() local content_length = nil
if not typ then content_length=tonumber(ngx.req.get_headers()['content-length'])
return local chunk_size = 4096
end if content_length < chunk_size then
if typ=="body" then chunk_size = content_length
body(res) end
end local size = 0
while size < content_length do
if typ == "eof" then local data, err, partial = sock:receive(chunk_size)
break data = data or partial
end 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 end
ngx.req.finish_body()
-- local typ, res, err = form:read() if body(data) then
-- body(res) return true
else end
else
ngx.req.read_body() ngx.req.read_body()
local args = ngx.req.get_post_args() local args = ngx.req.get_post_args()
if not args then if not args then

Loading…
Cancel
Save