-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_access_block.lua
More file actions
36 lines (31 loc) · 1.42 KB
/
custom_access_block.lua
File metadata and controls
36 lines (31 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
data = ngx.shared.data
-- my_data = {'proxy_cache_key', 'proxy_pass', 'proxy_hide_header', 'proxy_cache', 'proxy_temp_path', 'expired_time'}
h = ngx.req.get_headers()
prefix = h['prefix']
filename = h['filename']
function get_data(key)
f = io.open(filename, "rb")
if f == nill then
ngx.header["Erorr"] = "JSON FILE NOT FOUND"
return ngx.exit(404)
else
local content = f:read("*all")
f:close()
local cjson = require("cjson")
local value = cjson.decode(content)
for key,val in pairs(value) do
success, err, forcible = ngx.shared.data:set(key, val)
data[key] = val
if not success then
ngx.header["Erorr"] = "JSON FILE "..filename.."Cannot decode"
return ngx.exit(404)
end
end
end
return data:get(name)
end
ngx.var.cdn_proxy_cache_key = data:get(prefix.."proxy_cache_key") or get_data(prefix.."proxy_cache_key")
ngx.var.cdn_proxy_pass = data:get(prefix.."proxy_pass") or get_data(prefix.."proxy_pass")
ngx.var.cdn_proxy_hide_header = data:get(prefix.."proxy_hide_header") or get_data(prefix.."proxy_hide_header")
ngx.var.cdn_proxy_cache = data:get(prefix.."proxy_cache") or get_data(prefix.."proxy_cache")
ngx.var.cdn_proxy_temp_path = data:get(prefix.."proxy_temp_path") or get_data(prefix.."proxy_temp_path")