Skip to content

Commit

Permalink
add script as flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tzssangglass committed Oct 23, 2022
1 parent 85cd55c commit ad92b57
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
6 changes: 5 additions & 1 deletion apisix/plugins/ai.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ local function routes_analyze(routes)
route_flags["service_id"] = true
elseif key == "plugin_config_id" then
route_flags["plugin_config_id"] = true
elseif key == "script" then
route_flags["script"] = true
end

-- collect upstream flags
Expand Down Expand Up @@ -214,7 +216,8 @@ local function routes_analyze(routes)
end
end

local global_rules_flag = #router.global_rules.values ~= 0
local global_rules_flag = router.global_rules and router.global_rules.values
and #router.global_rules.values ~= 0

if route_flags["vars"] or route_flags["filter_fun"]
or route_flags["remote_addr"]
Expand All @@ -234,6 +237,7 @@ local function routes_analyze(routes)
end

if route_flags["service"]
or route_flags["script"]
or route_flags["service_id"]
or route_flags["upstream_id"]
or route_flags["enable_websocket"]
Expand Down
63 changes: 63 additions & 0 deletions t/plugin/ai2.t
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,66 @@ enable sample upstream
do body filter
--- no_error_log
enable sample upstream
=== TEST 5: exist global_rules, disable skip body filter
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/global_rules/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"serverless-pre-function": {
"phase": "before_proxy",
"functions" : ["return function(conf, ctx) ngx.log(ngx.WARN, \"run before_proxy phase balancer_ip : \", ctx.balancer_ip) end"]
}
}
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.sleep(0.5)
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
ngx.say(body)
return
end
ngx.sleep(0.5)
local http = require "resty.http"
local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/hello"
local httpc = http.new()
local res, err = httpc:request_uri(uri)
assert(res.status == 200)
if not res then
ngx.log(ngx.ERR, err)
return
end
ngx.say(res.body)
}
}
--- response_body
do body filter
--- error_log
run before_proxy phase balancer_ip : 127.0.0.1
--- no_error_log
enable sample upstream

0 comments on commit ad92b57

Please sign in to comment.