Skip to content

feat: Provide uri_arg_ when radixtree_uri_with_parameter#10645

Merged
juststillthinking merged 9 commits into
apache:masterfrom
boekkooi-lengoo:uri_args
Jan 12, 2024
Merged

feat: Provide uri_arg_ when radixtree_uri_with_parameter#10645
juststillthinking merged 9 commits into
apache:masterfrom
boekkooi-lengoo:uri_args

Conversation

@boekkooi-lengoo

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

@boekkooi-lengoo

Copy link
Copy Markdown
Contributor Author

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

@juststillthinking

Copy link
Copy Markdown
Contributor

@boekkooi-lengoo please make the ci pass

@moonming

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread apisix/core/ctx.lua Outdated
Comment thread apisix/core/ctx.lua Outdated
Comment thread apisix/core/ctx.lua Outdated
end
end

elseif core_str.has_prefix(key, "uri_arg_") then

Copy link
Copy Markdown
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?

@boekkooi-lengoo boekkooi-lengoo Dec 28, 2023

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Comment thread apisix/core/ctx.lua Outdated
Comment thread t/core/ctx_with_params.t Outdated
Comment thread t/core/ctx_with_params.t Outdated
Comment thread t/core/ctx_with_params.t Outdated
@juststillthinking juststillthinking 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
Copy Markdown
Contributor Author

Hey @monkeyDluffy6017

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

Thanks in advance.
Kind regards,
Warnar

@juststillthinking

Copy link
Copy Markdown
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
Copy Markdown
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?

@juststillthinking

Copy link
Copy Markdown
Contributor

please merge the master

@boekkooi-lengoo

Copy link
Copy Markdown
Contributor Author

@monkeyDluffy6017 Created merge commit 45ee4a2 as requested

@juststillthinking juststillthinking added approved and removed wait for update wait for the author's response in this issue/PR user responded labels Jan 12, 2024
@juststillthinking
juststillthinking merged commit c11782a into apache:master Jan 12, 2024
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

help request: about radixtree_uri_with_parameter

6 participants