Skip to content

Commit

Permalink
feat(patch): control the proxy_upstream in lua side
Browse files Browse the repository at this point in the history
  • Loading branch information
oowl committed Dec 18, 2024
1 parent 881525b commit f8f96a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lualib/resty/kong/upstream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ base.allows_subsystem("http")

ffi.cdef([[
int
ngx_http_lua_ffi_set_upstream_next(ngx_http_request_t *r, uint32_t next_upstream, char **err);
ngx_http_lua_ffi_set_next_upstream(ngx_http_request_t *r, uint32_t next_upstream, char **err);
]])

local type = type
Expand All @@ -46,7 +46,7 @@ local next_upstream_table = {
non_idempotent = 0x00004000,
}

function _M.set_upstream_next(...)
function _M.set_next_upstream(...)
local nargs = select("#", ...)
if nargs == 0 then
return "no argument"
Expand Down Expand Up @@ -74,7 +74,7 @@ function _M.set_upstream_next(...)
end

local err = ffi.new("char *[1]")
local rc = C.ngx_http_lua_ffi_set_upstream_next(r, next_upstream, err)
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])
Expand Down
2 changes: 1 addition & 1 deletion src/ngx_http_lua_kong_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ ngx_http_lua_kong_get_next_upstream_mask(ngx_http_request_t *r,
}

int
ngx_http_lua_ffi_set_upstream_next(ngx_http_request_t *r, ngx_uint_t next_upstream, char **err)
ngx_http_lua_ffi_set_next_upstream(ngx_http_request_t *r, ngx_uint_t next_upstream, char **err)
{
ngx_http_lua_kong_ctx_t *ctx;

Expand Down
4 changes: 2 additions & 2 deletions t/013-upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ __DATA__
--- response_body eval
["this is backend peer \$TEST_NGINX_RAND_PORT_4", "this is backend peer \$TEST_NGINX_RAND_PORT_4"]

=== TEST 3: lua resty.kong.upstream.set_upstream_next() behavior
=== TEST 3: lua resty.kong.upstream.set_next_upstream() behavior
--- http_config
upstream balancer {
server 127.0.0.1;
Expand Down Expand Up @@ -228,7 +228,7 @@ __DATA__
--- config
access_by_lua_block {
local upstream = require "resty.kong.upstream"
local err = upstream.set_upstream_next("error", "timeout", "http_500", "http_502", "http_503", "http_504", "http_404", "http_403", "http_429", "non_idempotent", "bala")
local err = upstream.set_next_upstream("error", "timeout", "http_500", "http_502", "http_503", "http_504", "http_404", "http_403", "http_429", "non_idempotent", "bala")
if err then
ngx.log(ngx.ERR, "failed to set upstream next: ", err)
return ngx.exit(503)
Expand Down

0 comments on commit f8f96a3

Please sign in to comment.