Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lua/tools.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
module("tools", package.seeall)
local ngx_re = require "ngx.re"

function split(s, p)
-- 字符串切割
local rt = {}
string.gsub(s, '[^' .. p .. ']+', function(w)
rt[#rt + 1] = w
--table.insert(rt, w)
end )

-- 对问号分割做转义
if p == "?" then
p = "\\?"
end

local res = ngx_re.split(s, p)
if res then
if res[1] == "" then
table.remove(res, 1)
end
rt = res
else
table.insert(rt, 1, s)
end

return rt
end

Expand Down
2 changes: 1 addition & 1 deletion lua/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function _M.set(real_new_uri)
for i, elem in ipairs(rewrite_conf[host]['rewrite_urls']) do
--local ret = tools.match(uri,elem['uri'])
--if ret then
local ret = tools.match('/'..svc_code,elem['uri'])
-- local ret = tools.match('/'..svc_code,elem['uri'])
if '/'..svc_code == elem['uri'] then
data [string.len(elem['uri'])] = elem['rewrite_upstream']
end
Expand Down