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' ])
3
2
local method = ngx .req .get_method ()
4
3
if whiteip () then
5
4
elseif blockip () then
@@ -15,30 +14,40 @@ elseif args() then
15
14
elseif cookie () then
16
15
elseif PostCheck then
17
16
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
23
23
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
37
45
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
42
51
ngx .req .read_body ()
43
52
local args = ngx .req .get_post_args ()
44
53
if not args then
0 commit comments