Skip to content

Commit

Permalink
update split
Browse files Browse the repository at this point in the history
  • Loading branch information
chronolaw committed May 29, 2024
1 parent b6ac910 commit 0234c51
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion kong.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@
#
# ```
# local template = require "resty.template"
# local split = require "kong.tools.utils".split
# local split = require "kong.tools.string".split
# ```
#
# To run the plugin, add the modules to the
Expand Down
4 changes: 1 addition & 3 deletions kong/clustering/compat/version.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
local utils = require("kong.tools.utils")

local type = type
local tonumber = tonumber
local split = utils.split
local split = require("kong.tools.string").split

local MAJOR_MINOR_PATTERN = "^(%d+)%.(%d+)%.%d+"

Expand Down
4 changes: 2 additions & 2 deletions kong/plugins/proxy-cache/handler.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local require = require
local cache_key = require "kong.plugins.proxy-cache.cache_key"
local utils = require "kong.tools.utils"
local kong_meta = require "kong.meta"
local mime_type = require "kong.tools.mime_type"
local nkeys = require "table.nkeys"
local split = require("kong.tools.string").split


local ngx = ngx
Expand Down Expand Up @@ -260,7 +260,7 @@ function ProxyCacheHandler:init_worker()
kong.cluster_events:subscribe("proxy-cache:purge", function(data)
kong.log.err("handling purge of '", data, "'")

local plugin_id, cache_key = unpack(utils.split(data, ":"))
local plugin_id, cache_key = unpack(split(data, ":"))
local plugin, err = kong.db.plugins:select({ id = plugin_id })
if err then
kong.log.err("error in retrieving plugins: ", err)
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/zipkin/request_tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- Will add two tags to the request span in Zipkin


local split = require "kong.tools.utils".split
local split = require "kong.tools.string".split

local match = string.match

Expand Down
7 changes: 3 additions & 4 deletions kong/runloop/events.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local utils = require "kong.tools.utils"
local constants = require "kong.constants"
local certificate = require "kong.runloop.certificate"
local balancer = require "kong.runloop.balancer"
Expand All @@ -11,7 +10,7 @@ local unpack = unpack
local ipairs = ipairs
local tonumber = tonumber
local fmt = string.format
local utils_split = utils.split
local split = require("kong.tools.string").split


local ngx = ngx
Expand Down Expand Up @@ -114,7 +113,7 @@ end

-- cluster event: "balancer:targets"
local function cluster_balancer_targets_handler(data)
local operation, key = unpack(utils_split(data, ":"))
local operation, key = unpack(split(data, ":"))

local entity = "all"
if key ~= "all" then
Expand Down Expand Up @@ -152,7 +151,7 @@ end


local function cluster_balancer_upstreams_handler(data)
local operation, ws_id, id, name = unpack(utils_split(data, ":"))
local operation, ws_id, id, name = unpack(split(data, ":"))
local entity = {
id = id,
name = name,
Expand Down
4 changes: 2 additions & 2 deletions kong/tools/emmy_debugger.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local pl_path = require "pl.path"
local utils = require "kong.tools.utils"
local split = require("kong.tools.string").split

local env_config = {
debugger = os.getenv("KONG_EMMY_DEBUGGER"),
Expand Down Expand Up @@ -64,7 +64,7 @@ local function init(config_)
local multi_worker = env_config.multi_worker or env_config.multi_worker

env_prefix = config.env_prefix or "KONG"
source_path = utils.split(config.source_path or env_config.source_path or "", ":")
source_path = split(config.source_path or env_config.source_path or "", ":")

if not debugger then
return
Expand Down
14 changes: 7 additions & 7 deletions spec/03-plugins/30-session/01-access_spec.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local utils = require "kong.tools.utils"
local constants = require "kong.constants"
local helpers = require "spec.helpers"
local cjson = require "cjson"
local lower = string.lower
local split = require("kong.tools.string").split

local REMEMBER_ROLLING_TIMEOUT = 3600

Expand Down Expand Up @@ -196,14 +196,14 @@ for _, strategy in helpers.each_strategy() do
client:close()

local cookie = assert.response(res).has.header("Set-Cookie")
local cookie_name = utils.split(cookie, "=")[1]
local cookie_name = split(cookie, "=")[1]
assert.equal("session", cookie_name)

-- e.g. ["Set-Cookie"] =
-- "da_cookie=m1EL96jlDyQztslA4_6GI20eVuCmsfOtd6Y3lSo4BTY|15434724
-- 06|U5W4A6VXhvqvBSf4G_v0-Q|DFJMMSR1HbleOSko25kctHZ44oo; Path=/
-- ; SameSite=Lax; Secure; HttpOnly"
local cookie_parts = utils.split(cookie, "; ")
local cookie_parts = split(cookie, "; ")
assert.equal("SameSite=Strict", cookie_parts[3])
assert.equal("Secure", cookie_parts[4])
assert.equal("HttpOnly", cookie_parts[5])
Expand Down Expand Up @@ -231,9 +231,9 @@ for _, strategy in helpers.each_strategy() do
client:close()

cookie = assert.response(res).has.header("Set-Cookie")
assert.equal("da_cookie", utils.split(cookie, "=")[1])
assert.equal("da_cookie", split(cookie, "=")[1])

local cookie_parts = utils.split(cookie, "; ")
local cookie_parts = split(cookie, "; ")
assert.equal("SameSite=Lax", cookie_parts[3])
assert.equal(nil, cookie_parts[4])
assert.equal(nil, cookie_parts[5])
Expand Down Expand Up @@ -261,14 +261,14 @@ for _, strategy in helpers.each_strategy() do
client:close()

local cookie = assert.response(res).has.header("Set-Cookie")
local cookie_name = utils.split(cookie[1], "=")[1]
local cookie_name = split(cookie[1], "=")[1]
assert.equal("session", cookie_name)

-- e.g. ["Set-Cookie"] =
-- "session=m1EL96jlDyQztslA4_6GI20eVuCmsfOtd6Y3lSo4BTY|15434724
-- 06|U5W4A6VXhvqvBSf4G_v0-Q|DFJMMSR1HbleOSko25kctHZ44oo; Expires=Mon, 06 Jun 2022 08:30:27 GMT;
-- Max-Age=3600; Path=/; SameSite=Lax; Secure; HttpOnly"
local cookie_parts = utils.split(cookie[2], "; ")
local cookie_parts = split(cookie[2], "; ")
print(cookie[2])
assert.equal("Path=/", cookie_parts[2])
assert.equal("SameSite=Strict", cookie_parts[3])
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/forward-proxy-server.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local _M = {}

local split = require("kong.tools.utils").split
local split = require("kong.tools.string").split

local header_mt = {
__index = function(self, name)
Expand Down
8 changes: 4 additions & 4 deletions spec/fixtures/mock_upstream.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local utils = require "kong.tools.utils"
local cjson_safe = require "cjson.safe"
local cjson = require "cjson"
local ws_server = require "resty.websocket.server"
local pl_stringx = require "pl.stringx"
local pl_file = require "pl.file"
local split = require("kong.tools.string").split


local kong = {
Expand All @@ -24,7 +24,7 @@ local function parse_multipart_form_params(body, content_type)
end

local boundary = m[1]
local parts_split = utils.split(body, '--' .. boundary)
local parts_split = split(body, '--' .. boundary)
local params = {}
local part, from, to, part_value, part_name, part_headers, first_header
for i = 1, #parts_split do
Expand All @@ -38,7 +38,7 @@ local function parse_multipart_form_params(body, content_type)

part_value = part:sub(to + 2, #part) -- +2: trim leading line jump
part_headers = part:sub(1, from - 1)
first_header = utils.split(part_headers, '\\n')[1]
first_header = split(part_headers, '\\n')[1]
if pl_stringx.startswith(first_header:lower(), "content-disposition") then
local m, err = ngx.re.match(first_header, 'name="(.*?)"', "oj")

Expand Down Expand Up @@ -114,7 +114,7 @@ local function find_http_credentials(authorization_header)
local decoded_basic = ngx.decode_base64(m[1])

if decoded_basic then
local user_pass = utils.split(decoded_basic, ":")
local user_pass = split(decoded_basic, ":")
return user_pass[1], user_pass[2]
end
end
Expand Down

0 comments on commit 0234c51

Please sign in to comment.