shenyu
shenyu copied to clipboard
[Task] RewritePlugin supports cross application
Description
Currently, RewritePlugin only supports rewrite url in the same application, this task needs RewritePlugin to supports rewrite url cross applications which accessed in shenyu.
Task List
- [ ] refactor RewritePlugin to support URL rewriting across applications.
- [x] support adjusting traffic percentage, default to 100% to ensure compatibility with older versions.
- [ ] refactor RewritePlugin to support URL rewriting across plugins.
Hi, I'd like to take this task, but before that, I have two questions:
- What is the RewritePlugin for?
- What is the definition of "application" in this context?
Hi, I'd like to take this task, but before that, I have two questions:
- What is the RewritePlugin for?
- What is the definition of "application" in this context?
For Q1: see https://shenyu.apache.org/docs/next/plugin-center/http-process/rewrite-plugin
For Q2: Application
refers to an application that is proxied by shenyu-gateway, just like shenyu-examples-http
Hi, Thanks for the explanation. After reading the blog, I have several follow up questions. First of all, there are several links which are not accessible. https://shenyu.apache.org/docs/next/plugin-center/user-guide/admin-usage/selector-and-rule https://shenyu.apache.org/docs/next/plugin-center/quick-start/quick-start-http#run-the-shenyu-examples-http-project
I have a general idea on what's the work of rewrite-plugin: it can help the customer to replace the sub-url to other string. For example: after opening the rewrite plugin, we can replace the http://localhost:9095/http/hello
to http://localhost:9095/hi
- Is this what the rewrite does? Do I miss any other functions of rewrite plugin?
- Do we have any real world example on the use of this plugin? It's hard for me to come up with one.
- What is the real world example of this task - support rewriting the url cross different application?
- How can we support rewriting the url cross different application? I didn't find how we differentiate the url from different application in the doExecute method.
- I noticed in the task list, you mentioned "support adjusting traffic percentage", how are we going to achieve that?
Sorry for so many questions, I just want to clarify everything before the implementation.
First of all, there are several links which are not accessible. https://shenyu.apache.org/docs/next/plugin-center/user-guide/admin-usage/selector-and-rule https://shenyu.apache.org/docs/next/plugin-center/quick-start/quick-start-http#run-the-shenyu-examples-http-project
About links problem, can you fix them in shenyu-website ?
For example: after opening the rewrite plugin, we can replace the http://localhost:9095/http/hello to http://localhost:9095/hi 1.Is this what the rewrite does? Do I miss any other functions of rewrite plugin?
yes
2.Do we have any real world example on the use of this plugin? It's hard for me to come up with one. 3.What is the real world example of this task - support rewriting the url cross different application?
Assuming you originally had one application that needed to be split into many applications
due to increasingly complex business, there would be a need for interface flow switching, and RewritePlugin would come in handy.
4.How can we support rewriting the url cross different application? I didn't find how we differentiate the url from different application in the doExecute method.
Tracking Constants.REWRITE_URI
, RewritePlugin
just put the attritube, use the attritube is in AbstractHttpClientPlugin#resend
.
5.I noticed in the task list, you mentioned "support adjusting traffic percentage", how are we going to achieve that?
In RewritePlugin
, the handle
, we need to add a percentage
(default 100) field, the percentage can be changed in shenyu-admin
, and the RewritePlugin
use percentage
to decide whether to put Constants.REWRITE_URI
.
I‘ve updated the doc, the latest doc link should be https://shenyu.apache.org/docs/plugin-center/http-process/rewrite-plugin/
rather than https://shenyu.apache.org/docs/next/plugin-center/http-process/rewrite-plugin
I read through the code base and find here(final URI newUri = RequestUrlUtils.buildRequestUri(exchange, upstream.buildDomain());
) we get the new URI which has already been rewritten. So can I assume after this step we finished the work of the RewritePlugin
?
My Question is:
- Can I assume each URI represent an application?
- What does the URI look like when there are several applications? And what does the URI look like after the rewrite? Could you provide an example?
I‘ve updated the doc, the latest doc link should be https://shenyu.apache.org/docs/plugin-center/http-process/rewrite-plugin/ rather than https://shenyu.apache.org/docs/next/plugin-center/http-process/rewrite-plugin
good job !
I read through the code base and find here(final URI newUri = RequestUrlUtils.buildRequestUri(exchange, upstream.buildDomain());) we get the new URI which has already been rewritten. So can I assume after this step we finished the work of the RewritePlugin?
Not just RewritePlugin
, the other usages like below should be all changed.
Can I assume each URI represent an application? What does the URI look like when there are several applications? And what does the URI look like after the rewrite? Could you provide an example?
shenyu-examples-http
had provide servers such as /http/order/**
(In OrderController
) and /http/upload/**
(In UploadController
).
Now we need to add 2 projects to replace shenyu-examples-http
, which named shenyu-examples-http-order
and shenyu-examples-http-upload
.
The original /http/order/**
needs to be rewritten as /http-order/order/**
, then the traffic can linked to shenyu-examples-http-order
(not the original shenyu-examples-http
project).
The same actions needs to be done like shenyu-examples-http-upload
.
Can you add my wechat Z18179469818
?
hi, @dragon-zhang ISSUE https://github.com/apache/shenyu/issues/4923 , I have a suggestion to adjust the execution order of the plugins. This(#4907) change will increase the priority of the rewrite plugin, which may cause external users' URLs to bypass the authentication plugin.