-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide
uri_arg_
when radixtree_uri_with_parameter
Add the prefix `uri_arg_` to the APISIX `ctx.var` allowing a APISIX configured to use the `radixtree_uri_with_parameter` router to access `opts.matched`. This allows the usage of the matches inside for example the `proxy_rewrite` plugin. Also see https://github.com/api7/lua-resty-radixtree/#parameters-in-path
- Loading branch information
1 parent
4db435e
commit cd13465
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
use t::APISIX 'no_plan'; | ||
|
||
repeat_each(1); | ||
no_long_string(); | ||
no_root_location(); | ||
no_shuffle(); | ||
|
||
our $yaml_config = <<_EOC_; | ||
apisix: | ||
router: | ||
http: 'radixtree_uri_with_parameter' | ||
_EOC_ | ||
|
||
add_block_preprocessor(sub { | ||
my ($block) = @_; | ||
|
||
if (!$block->yaml_config) { | ||
$block->set_value("yaml_config", $yaml_config); | ||
} | ||
}); | ||
|
||
run_tests; | ||
|
||
__DATA__ | ||
=== TEST 1: sanity | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local core = require("apisix.core") | ||
local ctx = {} | ||
core.ctx.set_vars_meta(ctx) | ||
ngx.say("remote_addr: ", ctx.var["remote_addr"]) | ||
ngx.say("server_port: ", ctx.var["server_port"]) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
remote_addr: 127.0.0.1 | ||
server_port: 1984 | ||
=== TEST 1: add route and get `uri_arg_` | ||
--- config | ||
location /t { | ||
content_by_lua_block { | ||
local t = require("lib.test_admin").test | ||
local code, body = t('/apisix/admin/routes/1', | ||
ngx.HTTP_PUT, | ||
[[{ | ||
"methods": ["GET"], | ||
"plugins": { | ||
"serverless-pre-function": { | ||
"phase": "access", | ||
"functions" : ["return function() ngx.log(ngx.INFO, \"uri_arg_path: \", ngx.ctx.api_ctx.var.uri_arg_path) end"] | ||
} | ||
}, | ||
"upstream": { | ||
"type": "roundrobin", | ||
"nodes": { | ||
"127.0.0.1:1980": 1 | ||
} | ||
}, | ||
"uri": "/:path" | ||
}]] | ||
) | ||
if code >= 300 then | ||
ngx.status = code | ||
end | ||
ngx.say(body) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
passed | ||
=== TEST 8: `uri_arg_path` exist | ||
--- request | ||
GET /hello | ||
--- response_body | ||
hello world | ||
--- error_log | ||
uri_arg_path: hello | ||