moonbridge
changeset 53:aaf67ef45c22
Timeout management
author | jbe |
---|---|
date | Sun Mar 22 13:19:54 2015 +0100 (2015-03-22) |
parents | 042bb4854aa6 |
children | e3df61bf62f4 |
files | moonbridge_http.lua |
line diff
1.1 --- a/moonbridge_http.lua Sun Mar 22 11:56:47 2015 +0100 1.2 +++ b/moonbridge_http.lua Sun Mar 22 13:19:54 2015 +0100 1.3 @@ -181,10 +181,29 @@ 1.4 -- desired chunk sizes: 1.5 local input_chunk_size = options.maximum_input_chunk_size or options.chunk_size or 16384 1.6 local output_chunk_size = options.minimum_output_chunk_size or options.chunk_size or 1024 1.7 + -- timeouts: 1.8 + local request_header_timeout = options.http_request_header_timeout 1.9 + local request_body_timeout = options.http_request_body_timeout 1.10 + local request_timeout = options.http_request_timeout 1.11 + local response_timeout = options.http_timeout 1.12 + if request_header_timeout == nil then 1.13 + request_header_timeout = 60 1.14 + end 1.15 + if response_timeout == nil then 1.16 + response_timeout = 60 1.17 + end 1.18 -- return connect handler: 1.19 return function(socket) 1.20 local survive = true -- set to false if process shall be terminated later 1.21 repeat 1.22 + -- timeout management: 1.23 + if request_header_timeout then 1.24 + timeout(request_header_timeout) 1.25 + elseif request_timeout then 1.26 + timeout(request_timeout) 1.27 + else 1.28 + timeout(0) 1.29 + end 1.30 -- process named arguments "request_header_size_limit" and "request_body_size_limit": 1.31 local remaining_header_size_limit = options.request_header_size_limit or 1024*1024 1.32 local remaining_body_size_limit = options.request_body_size_limit or 64*1024*1024 1.33 @@ -970,6 +989,15 @@ 1.34 request.cookies[decode_uri(rawkey)] = decode_uri(rawvalue) 1.35 end 1.36 end 1.37 + -- timeout management: 1.38 + if request_body_timeout then 1.39 + timeout(request_body_timeout) 1.40 + request:process_request_body() 1.41 + elseif request_timeout then 1.42 + timeout(request_timeout) 1.43 + request:process_request_body() 1.44 + end 1.45 + timeout(response_timeout or 0) 1.46 -- call underlying handler and remember boolean result: 1.47 if handler(request) ~= true then survive = false end 1.48 -- finish request (unless already done by underlying handler):