-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess.lua
42 lines (31 loc) · 974 Bytes
/
access.lua
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
37
38
39
40
41
42
local cjson = require "cjson"
local pl_tablex = require "pl.tablex"
local pl_copy_table = pl_tablex.deepcopy
local get_uri_args = kong.request.get_query
local set_uri_args = kong.service.request.set_query
local _M = {}
-- value是否存在于table中
local function is_exist(tab, value)
local revtab = {}
for _, v in pairs(tab) do
revtab[v] = true
end
return revtab[value]
end
function _M.execute(conf)
-- 获取所有url参数
local query_params = get_uri_args()
local querystring = pl_copy_table(query_params)
local json_table = {};
for k, v in pairs(query_params) do
if conf.exclude_params_names then
if not is_exist(conf.exclude_params_names, k) then
json_table[k] = v
querystring[k] = nil
end
end
querystring[conf.params_name] = cjson.encode(json_table)
end
set_uri_args(querystring)
end
return _M