add REQUEST_TIMEOUT config parameter
This commit is contained in:
parent
71c4247d6b
commit
580fab7b02
2 changed files with 23 additions and 3 deletions
|
@ -4,6 +4,7 @@ local config = require "config"
|
||||||
local lrucache = require "lrucache"
|
local lrucache = require "lrucache"
|
||||||
local logging = require "logging"
|
local logging = require "logging"
|
||||||
local log_file = require "logging.file"
|
local log_file = require "logging.file"
|
||||||
|
local socket = require "socket"
|
||||||
local http = require("socket.http")
|
local http = require("socket.http")
|
||||||
local https = require("ssl.https")
|
local https = require("ssl.https")
|
||||||
|
|
||||||
|
@ -71,6 +72,11 @@ function csmod.allowIp(ip)
|
||||||
protocol = "tlsv1",
|
protocol = "tlsv1",
|
||||||
options = "all",
|
options = "all",
|
||||||
verify = "none",
|
verify = "none",
|
||||||
|
create = function()
|
||||||
|
local req_sock = socket.tcp()
|
||||||
|
req_sock:settimeout(runtime.conf['REQUEST_TIMEOUT'], 't')
|
||||||
|
return req_sock
|
||||||
|
end
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
body, code, headers = http.request{
|
body, code, headers = http.request{
|
||||||
|
@ -81,7 +87,12 @@ function csmod.allowIp(ip)
|
||||||
['User-Agent'] = runtime.userAgent
|
['User-Agent'] = runtime.userAgent
|
||||||
},
|
},
|
||||||
content_type = 'application/json',
|
content_type = 'application/json',
|
||||||
sink = ltn12.sink.table(resp)
|
sink = ltn12.sink.table(resp),
|
||||||
|
create = function()
|
||||||
|
local req_sock = socket.tcp()
|
||||||
|
req_sock:settimeout(runtime.conf['REQUEST_TIMEOUT'], 't')
|
||||||
|
return req_sock
|
||||||
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,14 @@ end
|
||||||
|
|
||||||
function config.loadConfig(file)
|
function config.loadConfig(file)
|
||||||
if not config.file_exists(file) then
|
if not config.file_exists(file) then
|
||||||
return nil, "File".. file .." doesn't exist"
|
return nil, "File ".. file .." doesn't exist"
|
||||||
end
|
end
|
||||||
local conf = {}
|
local conf = {}
|
||||||
local valid_params = {'API_URL', 'API_KEY', 'LOG_FILE'}
|
local valid_params = {'API_URL', 'API_KEY', 'LOG_FILE'}
|
||||||
local valid_int_params = {'CACHE_EXPIRATION', 'CACHE_SIZE'}
|
local valid_int_params = {'CACHE_EXPIRATION', 'CACHE_SIZE', 'REQUEST_TIMEOUT'}
|
||||||
|
local default_values = {
|
||||||
|
['REQUEST_TIMEOUT'] = 0.2
|
||||||
|
}
|
||||||
for line in io.lines(file) do
|
for line in io.lines(file) do
|
||||||
local isOk = false
|
local isOk = false
|
||||||
if starts_with(line, "#") then
|
if starts_with(line, "#") then
|
||||||
|
@ -55,10 +58,16 @@ function config.loadConfig(file)
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
print("unsupported configuration '" .. v .. "'")
|
print("unsupported configuration '" .. v .. "'")
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
for k, v in pairs(default_values) do
|
||||||
|
if conf[k] == nil then
|
||||||
|
conf[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
return conf, nil
|
return conf, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue