Skip to content

Commit

Permalink
fix: fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed Dec 23, 2024
1 parent 72b0b9a commit d6e0352
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions lualib/resty/kong/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,55 +44,55 @@ local ffi_str = ffi.string
local NGX_OK = ngx.OK

local next_upstream_table = {
error = C.ngx_http_lua_kong_next_upstream_mask_error,
timeout = C.ngx_http_lua_kong_next_upstream_mask_timeout,
invalid_header = C.ngx_http_lua_kong_next_upstream_mask_invalid_header,
http_500 = C.ngx_http_lua_kong_next_upstream_mask_http_500,
http_502 = C.ngx_http_lua_kong_next_upstream_mask_http_502,
http_503 = C.ngx_http_lua_kong_next_upstream_mask_http_503,
http_504 = C.ngx_http_lua_kong_next_upstream_mask_http_504,
http_403 = C.ngx_http_lua_kong_next_upstream_mask_http_403,
http_404 = C.ngx_http_lua_kong_next_upstream_mask_http_404,
http_429 = C.ngx_http_lua_kong_next_upstream_mask_http_429,
off = C.ngx_http_lua_kong_next_upstream_mask_off,
non_idempotent = C.ngx_http_lua_kong_next_upstream_mask_non_idempotent,
error = C.ngx_http_lua_kong_next_upstream_mask_error,
timeout = C.ngx_http_lua_kong_next_upstream_mask_timeout,
invalid_header = C.ngx_http_lua_kong_next_upstream_mask_invalid_header,
http_500 = C.ngx_http_lua_kong_next_upstream_mask_http_500,
http_502 = C.ngx_http_lua_kong_next_upstream_mask_http_502,
http_503 = C.ngx_http_lua_kong_next_upstream_mask_http_503,
http_504 = C.ngx_http_lua_kong_next_upstream_mask_http_504,
http_403 = C.ngx_http_lua_kong_next_upstream_mask_http_403,
http_404 = C.ngx_http_lua_kong_next_upstream_mask_http_404,
http_429 = C.ngx_http_lua_kong_next_upstream_mask_http_429,
off = C.ngx_http_lua_kong_next_upstream_mask_off,
non_idempotent = C.ngx_http_lua_kong_next_upstream_mask_non_idempotent,
}

function _M.set_next_upstream(...)
local nargs = select("#", ...)
if nargs == 0 then
return "no argument"
end

local r = get_request()
if not r then
return "no request found"
end

local arg_table = { ... }
local next_upstream = 0
for i = 1, nargs do
local v = arg_table[i]
if type(v) ~= "string" then
return "argument #" .. i .. " is not a string"
end

local next_upstream_value = next_upstream_table[v]
if not next_upstream_value then
return "argument #" .. i .. " is not a valid argument"
end

next_upstream = bit.bor(next_upstream, next_upstream_value)
end

local err = ffi.new("char *[1]")
local rc = C.ngx_http_lua_ffi_set_next_upstream(r, next_upstream, err)

if rc ~= NGX_OK then
return "failed to set upstream next: " .. ffi_str(err[0])
end

return nil
local nargs = select("#", ...)
if nargs == 0 then
return "no argument"
end

local r = get_request()
if not r then
return "no request found"
end

local arg_table = { ... }
local next_upstream = 0
for i = 1, nargs do
local v = arg_table[i]
if type(v) ~= "string" then
return "argument #" .. i .. " is not a string"
end

local next_upstream_value = next_upstream_table[v]
if not next_upstream_value then
return "argument #" .. i .. " is not a valid argument"
end

next_upstream = bit.bor(next_upstream, next_upstream_value)
end

local err = ffi.new("char *[1]")
local rc = C.ngx_http_lua_ffi_set_next_upstream(r, next_upstream, err)

if rc ~= NGX_OK then
return "failed to set upstream next: " .. ffi_str(err[0])
end

return nil
end

return _M

0 comments on commit d6e0352

Please sign in to comment.