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

fix: declare peer_conn can only be used in the http subsystem #85

Merged
merged 6 commits into from
May 13, 2024
Merged
Changes from 3 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
50 changes: 27 additions & 23 deletions lualib/resty/kong/peer_conn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,39 @@ local errmsg = base.get_errmsg_ptr()
local C = ffi.C
local ffi_str = ffi.string
local get_phase = ngx.get_phase
tzssangglass marked this conversation as resolved.
Show resolved Hide resolved
local subsystem = ngx.config.subsystem
local NGX_ERROR = ngx.ERROR

local error = error


ffi.cdef[[
int
ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r,
char **err);
]]


local function get_last_peer_connection_cached()
if get_phase() ~= "balancer" then
error("get_last_peer_connection_cached() can only be called in balancer phase")
end

local r = get_request()
if not r then
error("no request found")
local get_last_peer_connection_cached


if subsystem == "http" then
chobits marked this conversation as resolved.
Show resolved Hide resolved
ffi.cdef[[
int ngx_http_lua_kong_ffi_get_last_peer_connection_cached(ngx_http_request_t *r,
char **err);
]]

get_last_peer_connection_cached = function()
if get_phase() ~= "balancer" then
error("get_last_peer_connection_cached() can only be called in balancer phase")
end

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

local rc = C.ngx_http_lua_kong_ffi_get_last_peer_connection_cached(r, errmsg)

if rc == NGX_ERROR then
error(ffi_str(errmsg[0]), 2)
end

return rc == 1
end

local rc = C.ngx_http_lua_kong_ffi_get_last_peer_connection_cached(r, errmsg)

if rc == NGX_ERROR then
error(ffi_str(errmsg[0]), 2)
end

return rc == 1
end

return {
Expand Down
Loading