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

feat: Provide uri_arg_ when radixtree_uri_with_parameter #10645

Merged
merged 9 commits into from
Jan 12, 2024

Conversation

boekkooi-lengoo
Copy link
Contributor

@boekkooi-lengoo boekkooi-lengoo commented Dec 13, 2023

Description

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

Fixes #10257

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

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
@moonming
Copy link
Member

@boekkooi-lengoo good catch 👍
Do we need to add more test cases for this PR?

@boekkooi-lengoo
Copy link
Contributor Author

@moonming I'm fine adding more just not sure which ones. Any suggestions what you think is missing?

@monkeyDluffy6017
Copy link
Contributor

@boekkooi-lengoo please make the ci pass

@moonming
Copy link
Member

@moonming I'm fine adding more just not sure which ones. Any suggestions what you think is missing?

@boekkooi-lengoo you can add a test case where the uri parameter does not exist and see the failure situation. Others are LGTM

Executed `find t -name '*.t' -exec ./utils/reindex '{}' \;` which should resolve the linting error.
To avoid unexpected behaviour a few extra test case have been added that ensure the following.
- `uri_arg_path` is actually dynamic and not hard coded to `hello`
- When `uri_arg_path` is pointing to an unknown route it's handled
- When a `uri_arg_<arg>` is not configured a warning is shown and an empty value (nil) is returned.
@boekkooi-lengoo
Copy link
Contributor Author

Good day @moonming and @monkeyDluffy6017,

Thanks for the review!
I added some extra test cases and a warning when a uri_arg_<name> is not found. As well as fixing the linting issue.

Please let me know if I missed anything 😄

@moonming
Copy link
Member

Good day @moonming and @monkeyDluffy6017,

Thanks for the review!

I added some extra test cases and a warning when a uri_arg_<name> is not found. As well as fixing the linting issue.

Please let me know if I missed anything 😄

great work. looks good to me👍

moonming
moonming previously approved these changes Dec 15, 2023
@@ -274,6 +274,15 @@ do
end
end

elseif core_str.has_prefix(key, "uri_arg_") then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uri_arg always means URL query arguments, maybe you should use uri_para_ instead?

Copy link
Contributor Author

@boekkooi-lengoo boekkooi-lengoo Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about uri_param_?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@monkeyDluffy6017 monkeyDluffy6017 added the wait for update wait for the author's response in this issue/PR label Dec 26, 2023
Naming is hard and as it's called parameter in the radix router we follow it's naming convention.
As there is no actual error (except one by the user) we avoid logging it.
It seems we don't need to check sanity so we remove it.
Ensure people know that `uri_param_` should only be used when `radixtree_uri_with_parameter` is in use.
@boekkooi-lengoo
Copy link
Contributor Author

Hey @monkeyDluffy6017

Can you please give the PR another look. I think all comments where addressed.

Thanks in advance.
Kind regards,
Warnar

@monkeyDluffy6017
Copy link
Contributor

please make the ci pass

Seems linting warning are errors in the ci
```
apisix/core/ctx.lua:278:101: line is too long (115 > 100)
```
@boekkooi-lengoo
Copy link
Contributor Author

Hey @monkeyDluffy6017

I fixed the linting issue but I can't reproduce the t/plugin/log-rotate.t error.
Any suggestions how to reproduce the issue?

@monkeyDluffy6017
Copy link
Contributor

please merge the master

@boekkooi-lengoo
Copy link
Contributor Author

@monkeyDluffy6017 Created merge commit 45ee4a2 as requested

@monkeyDluffy6017 monkeyDluffy6017 added approved and removed wait for update wait for the author's response in this issue/PR user responded labels Jan 12, 2024
@monkeyDluffy6017 monkeyDluffy6017 merged commit c11782a into apache:master Jan 12, 2024
44 checks passed
@boekkooi-lengoo boekkooi-lengoo deleted the uri_args branch January 12, 2024 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

help request: about radixtree_uri_with_parameter
6 participants