Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style(router): rename buffer_append to expression_append #11277

Merged
merged 1 commit into from
Jul 31, 2023
Merged
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
36 changes: 18 additions & 18 deletions kong/router/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ local single_header_buf = buffer.new(64)
-- sep: a seperator of expressions, like '&&'
-- idx: indicate whether or not to add 'sep'
-- for example, we should not add 'sep' for the first element in array
local function buffer_append(buf, sep, str, idx)
local function expression_append(buf, sep, str, idx)
if #buf > 0 and
(idx == nil or idx > 1)
then
Expand Down Expand Up @@ -118,17 +118,17 @@ local function gen_for_nets(ip_field, port_field, vals)
end

if not ip then
buffer_append(nets_buf, LOGICAL_OR, exp_port, i)
expression_append(nets_buf, LOGICAL_OR, exp_port, i)
goto continue
end

if not port then
buffer_append(nets_buf, LOGICAL_OR, exp_ip, i)
expression_append(nets_buf, LOGICAL_OR, exp_ip, i)
goto continue
end

buffer_append(nets_buf, LOGICAL_OR,
"(" .. exp_ip .. LOGICAL_AND .. exp_port .. ")", i)
expression_append(nets_buf, LOGICAL_OR,
"(" .. exp_ip .. LOGICAL_AND .. exp_port .. ")", i)

::continue::
end -- for
Expand Down Expand Up @@ -166,7 +166,7 @@ local function get_expression(route)
gen = "(net.protocol != \"https\"" .. LOGICAL_OR .. gen .. ")"
end

buffer_append(expr_buf, LOGICAL_AND, gen)
expression_append(expr_buf, LOGICAL_AND, gen)
end

-- stream expression
Expand All @@ -176,11 +176,11 @@ local function get_expression(route)
local dst_gen = gen_for_nets("net.dst.ip", "net.dst.port", dsts)

if src_gen then
buffer_append(expr_buf, LOGICAL_AND, src_gen)
expression_append(expr_buf, LOGICAL_AND, src_gen)
end

if dst_gen then
buffer_append(expr_buf, LOGICAL_AND, dst_gen)
expression_append(expr_buf, LOGICAL_AND, dst_gen)
end

if src_gen or dst_gen then
Expand All @@ -192,7 +192,7 @@ local function get_expression(route)

local gen = gen_for_field("http.method", OP_EQUAL, methods)
if gen then
buffer_append(expr_buf, LOGICAL_AND, gen)
expression_append(expr_buf, LOGICAL_AND, gen)
end

if not is_empty_field(hosts) then
Expand All @@ -218,11 +218,11 @@ local function get_expression(route)
exp = "(" .. exp .. LOGICAL_AND ..
"net.port ".. OP_EQUAL .. " " .. port .. ")"
end
buffer_append(hosts_buf, LOGICAL_OR, exp, i)
expression_append(hosts_buf, LOGICAL_OR, exp, i)
end -- for route.hosts

buffer_append(expr_buf, LOGICAL_AND,
hosts_buf:put(")"):get())
expression_append(expr_buf, LOGICAL_AND,
hosts_buf:put(")"):get())
end

gen = gen_for_field("http.path", function(path)
Expand All @@ -238,7 +238,7 @@ local function get_expression(route)
return p
end)
if gen then
buffer_append(expr_buf, LOGICAL_AND, gen)
expression_append(expr_buf, LOGICAL_AND, gen)
end

if not is_empty_field(headers) then
Expand All @@ -257,15 +257,15 @@ local function get_expression(route)
op = OP_REGEX
end

buffer_append(single_header_buf, LOGICAL_OR,
name .. " " .. op .. " " .. escape_str(value:lower()), i)
expression_append(single_header_buf, LOGICAL_OR,
name .. " " .. op .. " " .. escape_str(value:lower()), i)
end

buffer_append(headers_buf, LOGICAL_AND,
single_header_buf:put(")"):get())
expression_append(headers_buf, LOGICAL_AND,
single_header_buf:put(")"):get())
end

buffer_append(expr_buf, LOGICAL_AND, headers_buf:get())
expression_append(expr_buf, LOGICAL_AND, headers_buf:get())
end

return expr_buf:get()
Expand Down
Loading