Update waf.lua

pull/23/head
loveshell 2013-12-12 17:40:23 +08:00
parent 047e0278f9
commit ed6b345db3
1 changed files with 33 additions and 24 deletions

41
waf.lua
View File

@ -1,4 +1,3 @@
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
@ -17,27 +16,37 @@ 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()
if not sock then
return 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'])
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 return
end end
if typ=="body" then ngx.req.append_body(data)
body(res) size = size + len(data)
end local less = content_length - size
if less < chunk_size then
if typ == "eof" then chunk_size = less
break
end end
end end
ngx.req.finish_body()
-- local typ, res, err = form:read() if body(data) then
-- body(res) return true
end
else else
ngx.req.read_body() ngx.req.read_body()
local args = ngx.req.get_post_args() local args = ngx.req.get_post_args()