You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2021/07/02 07:58:58 UTC
[incubator-shenyu] branch master updated: [ISSUE #1292] add
ModifyResponsePlugin (#1697)
This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new b71b78a [ISSUE #1292] add ModifyResponsePlugin (#1697)
b71b78a is described below
commit b71b78a1e51cebfe3cdd29b256757d499521aa58
Author: Bruce.Du <34...@qq.com>
AuthorDate: Fri Jul 2 15:58:46 2021 +0800
[ISSUE #1292] add ModifyResponsePlugin (#1697)
* add ParamResponse plugin
* add ParamResponse plugin
* update paramresponse to modifyresponse
* update response body
* add ModifyResponse plugin
* add license for pom
* update modifyResponsePlugin sql
---
.../src/main/resources/META-INF/schema.h2.sql | 31 ++++
.../src/main/resources/META-INF/schema.sql | 31 ++++
shenyu-bootstrap/pom.xml | 24 +++
.../rule/impl/ModifyResponseRuleHandle.java | 88 +++++++++
.../org/apache/shenyu/common/enums/PluginEnum.java | 5 +
shenyu-plugin/pom.xml | 1 +
.../shenyu-plugin-modify-response/pom.xml | 59 ++++++
.../plugin/response/ModifyResponsePlugin.java | 205 +++++++++++++++++++++
.../cache/ModifyResponseRuleHandleCache.java | 52 ++++++
.../handler/ModifyResponsePluginDataHandler.java | 63 +++++++
.../response/strategy/WebClientMessageWriter.java | 1 -
.../shenyu-spring-boot-starter-plugin/pom.xml | 1 +
.../pom.xml | 53 ++++++
.../ModifyResponsePluginConfiguration.java | 52 ++++++
.../src/main/resources/META-INF/spring.factories | 19 ++
.../src/main/resources/META-INF/spring.provides | 18 ++
16 files changed, 702 insertions(+), 1 deletion(-)
diff --git a/shenyu-admin/src/main/resources/META-INF/schema.h2.sql b/shenyu-admin/src/main/resources/META-INF/schema.h2.sql
index 2cb5db0..0cf4832 100644
--- a/shenyu-admin/src/main/resources/META-INF/schema.h2.sql
+++ b/shenyu-admin/src/main/resources/META-INF/schema.h2.sql
@@ -316,6 +316,7 @@ INSERT INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`, `date_c
INSERT INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`, `date_created`, `date_updated`) VALUES ('20', 'request', 'http process', 4, '0', '2021-05-26 21:38:48', '2021-05-30 19:55:22');
INSERT INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`, `date_created`, `date_updated`) VALUES ('21', 'oauth2', 'authentication', 10, '0', '2021-06-18 10:53:42', '2021-06-18 10:53:42');
INSERT INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`, `date_created`, `date_updated`) VALUES ('22', 'param_mapping','http process', 5,'{"ruleHandlePageType":"custom"}', '0', '2021-06-17 22:34:44', '2021-06-17 22:36:00');
+INSERT INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`, `date_created`, `date_updated`) VALUES ('23', 'modifyResponse', '1',23, '{"ruleHandlePageType":"custom"}', '0', '2021-05-30 21:26:37', '2021-05-30 23:26:11');
/**default admin user**/
INSERT INTO `dashboard_user` (`id`, `user_name`, `password`, `role`, `enabled`, `date_created`, `date_updated`) VALUES ('1','admin','jHcpKkiDbbQh7W7hh8yQSA==', '1', '1', '2018-06-23 15:12:22', '2018-06-23 15:12:23');
@@ -432,6 +433,12 @@ INSERT INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`
INSERT INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`date_created`,`date_updated`) VALUES ('1001', '14', 'contextPath', 'contextPath', 2, 2, 0, '2020-12-25 16:13:09', '2020-12-25 16:13:09');
INSERT INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`date_created`,`date_updated`) VALUES ('1002', '14', 'addPrefix', 'addPrefix', 2, 2, 0, '2020-12-25 16:13:09', '2020-12-25 16:13:09');
+/*insert plugin_handle data for request*/
+INSERT INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`,`date_created`,`date_updated`) VALUES ('86', '20', 'ruleHandlePageType', 'ruleHandlePageType', 3, 3, 0, '{"required":"0","rule":""}', '2021-05-27 23:43:53', '2021-05-30 19:58:28');
+
+/*insert plugin_handle data for ModifyResponse*/
+INSERT INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`,`date_created`,`date_updated`) VALUES ('87', '23', 'statusCode', 'status code', 1, 2, 1, '{\"required\":\"0\",\"rule\":\"/^[1-5]\\\\d{2}$/\"}', '2021-05-30 21:42:56', '2021-05-30 22:08:37');
+
/** insert permission role for role */
INSERT INTO `role` (`id`,`role_name`,`description`,`date_created`,`date_updated`) VALUES ('1346358560427216896', 'super', '超级管理员', '2021-01-05 01:31:10', '2021-01-08 17:00:07');
INSERT INTO `role` (`id`,`role_name`,`description`,`date_created`,`date_updated`) VALUES ('1385482862971723776', 'default', '普通用户', '2021-04-23 14:37:10', '2021-04-23 14:38:39');
@@ -698,6 +705,18 @@ INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`,
INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES('1397547768292343808', '1397547768158126080', 'SHENYU.BUTTON.PLUGIN.RULE.QUERY', '', '', '', 2, 0, '', 1, 0, 'plugin:requestRule:query', 1, '2021-05-26 21:38:48', '2021-05-26 21:38:47');
INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES('1397547768296538112', '1397547768158126080', 'SHENYU.BUTTON.PLUGIN.SYNCHRONIZE', '', '', '', 2, 0, '', 1, 0, 'plugin:request:modify', 1, '2021-05-26 21:38:48', '2021-05-26 21:38:47');
+/** insert ModifyResponse plugin's resource */
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252528254976', '1346775491550474240', 'modifyResponse', 'modifyResponse', '/plug/modifyResponse', 'modifyResponse', 1, 0, 'block', 0, 0, '', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252566003712', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SELECTOR.ADD', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseSelector:add', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252582780928', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SELECTOR.DELETE', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseSelector:delete', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252591169536', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SELECTOR.EDIT', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseSelector:edit', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252603752448', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SELECTOR.QUERY', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseSelector:query', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252620529664', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.RULE.ADD', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseRule:add', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252645695488', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.RULE.DELETE', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseRule:delete', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252658278400', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.RULE.EDIT', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseRule:edit', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252666667008', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.RULE.QUERY', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseRule:query', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252679249920', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SYNCHRONIZE', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponse:modify', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+
/** insert jwt plugin's resource */
INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1347028169120821250', '1346775491550474240', 'jwt', 'jwt', '/plug/jwt', 'jwt', 1, 16, 'key', 0, 0, '', 1, '2021-06-18 21:00:00', '2021-06-18 21:00:00');
INSERT INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES('1390309613569036001', '1347028169120821250', 'SHENYU.BUTTON.PLUGIN.SELECTOR.QUERY', '', '', '', 2, 0, '', 1, 0, 'plugin:jwtSelector:query', 1, '2021-05-06 22:16:57', '2021-05-06 22:37:00');
@@ -981,6 +1000,18 @@ INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `dat
INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1397547768292343809', '1346358560427216896', '1397547768292343808', '2021-05-26 21:38:48', '2021-05-26 21:38:47');
INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1397547768300732416', '1346358560427216896', '1397547768296538112', '2021-05-26 21:38:48', '2021-05-26 21:38:47');
+/** add ModifyResponse plugin's permissions */
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252532449280', '1346358560427216896', '1398994252528254976', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252570198016', '1346358560427216896', '1398994252566003712', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252582780929', '1346358560427216896', '1398994252582780928', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252591169537', '1346358560427216896', '1398994252591169536', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252603752449', '1346358560427216896', '1398994252603752448', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252620529665', '1346358560427216896', '1398994252620529664', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252645695489', '1346358560427216896', '1398994252645695488', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252658278401', '1346358560427216896', '1398994252658278400', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252666667009', '1346358560427216896', '1398994252666667008', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252679249921', '1346358560427216896', '1398994252679249920', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+
/** add jwt plugin's permissions */
INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1397547768300732010', '1346358560427216896', '1347028169120821250', '2021-05-26 21:38:48', '2021-05-26 21:38:47');
INSERT INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1397547768162320001', '1346358560427216896', '1397547768204263112', '2021-05-26 21:38:48', '2021-05-26 21:38:47');
diff --git a/shenyu-admin/src/main/resources/META-INF/schema.sql b/shenyu-admin/src/main/resources/META-INF/schema.sql
index 970bc19..76bae20 100644
--- a/shenyu-admin/src/main/resources/META-INF/schema.sql
+++ b/shenyu-admin/src/main/resources/META-INF/schema.sql
@@ -320,6 +320,7 @@ INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`,
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`, `date_created`, `date_updated`) VALUES ('20', 'request', 'http process', 4, '0', '2021-05-26 21:38:48', '2021-05-30 19:55:22');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `enabled`, `date_created`, `date_updated`) VALUES ('21', 'oauth2', 'authentication', 10, '0', '2021-06-18 10:53:42', '2021-06-18 10:53:42');
INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`, `date_created`, `date_updated`) VALUES ('22', 'param_mapping','http process', 5,'{"ruleHandlePageType":"custom"}', '0', '2021-06-17 22:34:44', '2021-06-17 22:36:00');
+INSERT IGNORE INTO `plugin` (`id`, `name`, `role`, `sort`, `config`, `enabled`, `date_created`, `date_updated`) VALUES ('23', 'modifyResponse', '1',23, '{"ruleHandlePageType":"custom"}', '0', '2021-05-30 21:26:37', '2021-05-30 23:26:11');
/**default admin user**/
INSERT IGNORE INTO `dashboard_user` (`id`, `user_name`, `password`, `role`, `enabled`, `date_created`, `date_updated`) VALUES ('1','admin','jHcpKkiDbbQh7W7hh8yQSA==', '1', '1', '2018-06-23 15:12:22', '2018-06-23 15:12:23');
@@ -435,6 +436,12 @@ INSERT IGNORE INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`
INSERT IGNORE INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`date_created`,`date_updated`) VALUES ('1001', '14', 'contextPath', 'contextPath', 2, 2, 0, '2020-12-25 16:13:09', '2020-12-25 16:13:09');
INSERT IGNORE INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`date_created`,`date_updated`) VALUES ('1002', '14', 'addPrefix', 'addPrefix', 2, 2, 0, '2020-12-25 16:13:09', '2020-12-25 16:13:09');
+/*insert plugin_handle data for request*/
+INSERT IGNORE INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`,`date_created`,`date_updated`) VALUES ('86', '20', 'ruleHandlePageType', 'ruleHandlePageType', 3, 3, 0, '{"required":"0","rule":""}', '2021-05-27 23:43:53', '2021-05-30 19:58:28');
+
+/*insert plugin_handle data for ModifyResponse*/
+INSERT IGNORE INTO plugin_handle (`id`,`plugin_id`,`field`,`label`,`data_type`,`type`,`sort`,`ext_obj`,`date_created`,`date_updated`) VALUES ('87', '23', 'statusCode', 'status code', 1, 2, 1, '{\"required\":\"0\",\"rule\":\"/^[1-5]\\\\d{2}$/\"}', '2021-05-30 21:42:56', '2021-05-30 22:08:37');
+
/** insert permission role for role */
INSERT IGNORE INTO `role` (`id`,`role_name`,`description`,`date_created`,`date_updated`) VALUES ('1346358560427216896', 'super', '超级管理员', '2021-01-05 01:31:10', '2021-01-08 17:00:07');
INSERT IGNORE INTO `role` (`id`,`role_name`,`description`,`date_created`,`date_updated`) VALUES ('1385482862971723776', 'default', '普通用户', '2021-04-23 14:37:10', '2021-04-23 14:38:39');
@@ -698,6 +705,18 @@ INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `compo
INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES('1397547768292343808', '1397547768158126080', 'SHENYU.BUTTON.PLUGIN.RULE.QUERY', '', '', '', 2, 0, '', 1, 0, 'plugin:requestRule:query', 1, '2021-05-26 21:38:48', '2021-05-26 21:38:47');
INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES('1397547768296538112', '1397547768158126080', 'SHENYU.BUTTON.PLUGIN.SYNCHRONIZE', '', '', '', 2, 0, '', 1, 0, 'plugin:request:modify', 1, '2021-05-26 21:38:48', '2021-05-26 21:38:47');
+/** insert ModifyResponse plugin's resource */
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252528254976', '1346775491550474240', 'modifyResponse', 'modifyResponse', '/plug/modifyResponse', 'modifyResponse', 1, 0, 'block', 0, 0, '', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252566003712', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SELECTOR.ADD', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseSelector:add', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252582780928', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SELECTOR.DELETE', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseSelector:delete', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252591169536', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SELECTOR.EDIT', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseSelector:edit', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252603752448', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SELECTOR.QUERY', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseSelector:query', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252620529664', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.RULE.ADD', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseRule:add', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252645695488', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.RULE.DELETE', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseRule:delete', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252658278400', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.RULE.EDIT', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseRule:edit', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252666667008', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.RULE.QUERY', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponseRule:query', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1398994252679249920', '1398994252528254976', 'SHENYU.BUTTON.PLUGIN.SYNCHRONIZE', '', '', '', 2, 0, '', 1, 0, 'plugin:modifyResponse:modify', 1, '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+
/** insert jwt plugin's resource */
INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES ('1347028169120821250', '1346775491550474240', 'jwt', 'jwt', '/plug/jwt', 'jwt', 1, 16, 'key', 0, 0, '', 1, '2021-06-18 21:00:00', '2021-06-18 21:00:00');
INSERT IGNORE INTO `resource` (`id`, `parent_id`, `title`, `name`, `url`, `component`, `resource_type`, `sort`, `icon`, `is_leaf`, `is_route`, `perms`, `status`, `date_created`, `date_updated`) VALUES('1390309613569036001', '1347028169120821250', 'SHENYU.BUTTON.PLUGIN.SELECTOR.QUERY', '', '', '', 2, 0, '', 1, 0, 'plugin:jwtSelector:query', 1, '2021-05-06 22:16:57', '2021-05-06 22:37:00');
@@ -984,6 +1003,18 @@ INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created
INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1397547768292343809', '1346358560427216896', '1397547768292343808', '2021-05-26 21:38:48', '2021-05-26 21:38:47');
INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1397547768300732416', '1346358560427216896', '1397547768296538112', '2021-05-26 21:38:48', '2021-05-26 21:38:47');
+/** add ModifyResponse plugin's permissions */
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252532449280', '1346358560427216896', '1398994252528254976', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252570198016', '1346358560427216896', '1398994252566003712', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252582780929', '1346358560427216896', '1398994252582780928', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252591169537', '1346358560427216896', '1398994252591169536', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252603752449', '1346358560427216896', '1398994252603752448', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252620529665', '1346358560427216896', '1398994252620529664', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252645695489', '1346358560427216896', '1398994252645695488', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252658278401', '1346358560427216896', '1398994252658278400', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252666667009', '1346358560427216896', '1398994252666667008', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1398994252679249921', '1346358560427216896', '1398994252679249920', '2021-05-30 21:26:37', '2021-05-30 21:26:36');
+
/** add jwt plugin's permissions */
INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1397547768300732010', '1346358560427216896', '1347028169120821250', '2021-05-26 21:38:48', '2021-05-26 21:38:47');
INSERT IGNORE INTO `permission` (`id`, `object_id`, `resource_id`, `date_created`, `date_updated`) VALUES ('1397547768162320001', '1346358560427216896', '1397547768204263112', '2021-05-26 21:38:48', '2021-05-26 21:38:47');
diff --git a/shenyu-bootstrap/pom.xml b/shenyu-bootstrap/pom.xml
index c53348f..0621932 100644
--- a/shenyu-bootstrap/pom.xml
+++ b/shenyu-bootstrap/pom.xml
@@ -347,6 +347,30 @@
</dependency>
<!--shenyu debug plugin end-->
+ <!-- shenyu modify response plugin start-->
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-modify-response</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- shenyu modify response plugin end-->
+
+ <!-- shenyu response plugin start-->
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-response</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- shenyu response plugin end-->
+
+ <!--shenyu request plugin start-->
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin-request</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!--shenyu request plugin end-->
+
<!--shenyu param mapping plugin start-->
<dependency>
<groupId>org.apache.shenyu</groupId>
diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/impl/ModifyResponseRuleHandle.java b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/impl/ModifyResponseRuleHandle.java
new file mode 100644
index 0000000..94a3d0e
--- /dev/null
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/impl/ModifyResponseRuleHandle.java
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+package org.apache.shenyu.common.dto.convert.rule.impl;
+
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+import org.apache.shenyu.common.dto.convert.rule.RuleHandle;
+import org.springframework.http.HttpStatus;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * The type ModifyResponse rule handle.
+ */
+@ToString
+@Getter
+@Setter
+@NoArgsConstructor
+public class ModifyResponseRuleHandle implements RuleHandle {
+
+ private static final long serialVersionUID = -3863724068338111444L;
+
+ /**
+ * add header map.
+ */
+ private Map<String, String> addHeaders;
+
+ /**
+ * set header map.
+ */
+ private Map<String, String> setHeaders;
+
+ /**
+ * replace header map
+ * key: oldHeaderKey, value: newHeaderKey.
+ */
+ private Map<String, String> replaceHeaderKeys;
+
+ /**
+ * remove header List.
+ */
+ private Set<String> removeHeaderKeys;
+
+ /**
+ * http response status code.
+ */
+ private int statusCode;
+
+ /**
+ * add body List.
+ */
+ private List<ParamMappingHandle.ParamMapInfo> addBodyKeys;
+
+ /**
+ * replace body List.
+ */
+ private List<ParamMappingHandle.ParamMapInfo> replaceBodyKeys;
+
+ /**
+ * remove body List.
+ */
+ private Set<String> removeBodyKeys;
+
+ @Override
+ public RuleHandle createDefault(final String path) {
+ this.statusCode = HttpStatus.OK.value();
+ return this;
+ }
+}
diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
index 504a05b..c19f2cc 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/enums/PluginEnum.java
@@ -86,6 +86,11 @@ public enum PluginEnum {
REQUEST(42, 0, "request"),
/**
+ * ModifyResponse plugin enum.
+ */
+ MODIFY_RESPONSE(44, 0, "modifyResponse"),
+
+ /**
* Hystrix plugin enum.
*/
HYSTRIX(45, 0, "hystrix"),
diff --git a/shenyu-plugin/pom.xml b/shenyu-plugin/pom.xml
index ead3533..5567a16 100644
--- a/shenyu-plugin/pom.xml
+++ b/shenyu-plugin/pom.xml
@@ -53,6 +53,7 @@
<module>shenyu-plugin-dubbo-common</module>
<module>shenyu-plugin-motan</module>
<module>shenyu-plugin-logging</module>
+ <module>shenyu-plugin-modify-response</module>
<module>shenyu-plugin-request</module>
<module>shenyu-plugin-oauth2</module>
<module>shenyu-plugin-jwt</module>
diff --git a/shenyu-plugin/shenyu-plugin-modify-response/pom.xml b/shenyu-plugin/shenyu-plugin-modify-response/pom.xml
new file mode 100644
index 0000000..5c14c19
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-modify-response/pom.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>shenyu-plugin</artifactId>
+ <groupId>org.apache.shenyu</groupId>
+ <version>2.4.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>shenyu-plugin-modify-response</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-plugin-base</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.projectreactor</groupId>
+ <artifactId>reactor-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.jayway.jsonpath</groupId>
+ <artifactId>json-path</artifactId>
+ <version>2.4.0</version>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/ModifyResponsePlugin.java b/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/ModifyResponsePlugin.java
new file mode 100644
index 0000000..c995068
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/ModifyResponsePlugin.java
@@ -0,0 +1,205 @@
+/*
+ * 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.
+ */
+
+package org.apache.shenyu.plugin.response;
+
+import com.jayway.jsonpath.DocumentContext;
+import com.jayway.jsonpath.JsonPath;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.shenyu.common.constant.Constants;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.common.dto.convert.rule.impl.ModifyResponseRuleHandle;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.CollectionUtils;
+import org.apache.shenyu.plugin.api.ShenyuPluginChain;
+import org.apache.shenyu.plugin.api.context.ShenyuContext;
+import org.apache.shenyu.plugin.base.AbstractShenyuPlugin;
+import org.apache.shenyu.plugin.base.support.BodyInserterContext;
+import org.apache.shenyu.plugin.base.support.CachedBodyOutputMessage;
+import org.apache.shenyu.plugin.response.cache.ModifyResponseRuleHandleCache;
+import org.apache.shenyu.plugin.response.handler.ModifyResponsePluginDataHandler;
+import org.reactivestreams.Publisher;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.core.io.buffer.DataBufferUtils;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.ReactiveHttpOutputMessage;
+import org.springframework.http.codec.ServerCodecConfigurer;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.http.server.reactive.ServerHttpResponseDecorator;
+import org.springframework.web.reactive.function.BodyInserter;
+import org.springframework.web.reactive.function.BodyInserters;
+import org.springframework.web.reactive.function.client.ClientResponse;
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.util.annotation.NonNull;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+
+/**
+ * ModifyResponse plugin.
+ */
+@Slf4j
+public class ModifyResponsePlugin extends AbstractShenyuPlugin {
+
+ public ModifyResponsePlugin() {
+
+ }
+
+ @Override
+ protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
+ if (Objects.isNull(rule)) {
+ return Mono.empty();
+ }
+ final ShenyuContext soulContext = exchange.getAttribute(Constants.CONTEXT);
+ assert soulContext != null;
+ final ModifyResponseRuleHandle modifyResponseRuleHandle = ModifyResponseRuleHandleCache.getInstance().obtainHandle(ModifyResponsePluginDataHandler.getResourceName(rule));
+
+ if (Objects.nonNull(modifyResponseRuleHandle)) {
+ ServerHttpResponse response = exchange.getResponse();
+ HttpHeaders httpHeaders = response.getHeaders();
+ if (Objects.nonNull(modifyResponseRuleHandle.getAddHeaders()) && MapUtils.isNotEmpty(modifyResponseRuleHandle.getAddHeaders())) {
+ Map<String, String> addHeaderMap = modifyResponseRuleHandle.getAddHeaders();
+ addHeaderMap.entrySet().stream().forEach(a -> httpHeaders.add(a.getKey(), a.getValue()));
+ }
+
+ if (Objects.nonNull(modifyResponseRuleHandle.getSetHeaders()) && MapUtils.isNotEmpty(modifyResponseRuleHandle.getSetHeaders())) {
+ Map<String, String> setHeaderMap = modifyResponseRuleHandle.getSetHeaders();
+ setHeaderMap.entrySet().stream().forEach(a -> httpHeaders.set(a.getKey(), a.getValue()));
+ }
+
+ if (Objects.nonNull(modifyResponseRuleHandle.getReplaceHeaderKeys()) && MapUtils.isNotEmpty(modifyResponseRuleHandle.getReplaceHeaderKeys())) {
+ Map<String, String> replaceHeaderMap = modifyResponseRuleHandle.getReplaceHeaderKeys();
+ replaceHeaderMap.entrySet().stream().forEach(a -> {
+ httpHeaders.addAll(a.getValue(), httpHeaders.get(a.getKey()));
+ httpHeaders.remove(a.getKey());
+ });
+ }
+
+ if (Objects.nonNull(modifyResponseRuleHandle.getRemoveHeaderKeys()) && !CollectionUtils.isEmpty(modifyResponseRuleHandle.getRemoveHeaderKeys())) {
+ Set<String> removeHeaderList = modifyResponseRuleHandle.getRemoveHeaderKeys();
+ removeHeaderList.stream().forEach(a -> httpHeaders.remove(a));
+ }
+
+ ClientResponse clientResponse = exchange.getAttribute(Constants.CLIENT_RESPONSE_ATTR);
+ if (modifyResponseRuleHandle.getStatusCode() > 0) {
+ response.setStatusCode(HttpStatus.valueOf(modifyResponseRuleHandle.getStatusCode()));
+ } else {
+ response.setStatusCode(clientResponse.statusCode());
+ }
+ }
+
+ return chain.execute(exchange.mutate()
+ .response(new ModifyServerHttpResponse(exchange, modifyResponseRuleHandle)).build());
+ }
+
+ @Override
+ public int getOrder() {
+ return PluginEnum.MODIFY_RESPONSE.getCode();
+ }
+
+ @Override
+ public String named() {
+ return PluginEnum.MODIFY_RESPONSE.getName();
+ }
+
+ static class ModifyServerHttpResponse extends ServerHttpResponseDecorator {
+
+ private final ServerWebExchange exchange;
+
+ private final ModifyResponseRuleHandle handle;
+
+ ModifyServerHttpResponse(final ServerWebExchange exchange, final ModifyResponseRuleHandle handle) {
+ super(exchange.getResponse());
+ this.exchange = exchange;
+ this.handle = handle;
+ }
+
+ @Override
+ @NonNull
+ public Mono<Void> writeWith(@NonNull final Publisher<? extends DataBuffer> body) {
+ HttpHeaders httpHeaders = new HttpHeaders();
+ httpHeaders.setContentType(MediaType.APPLICATION_JSON);
+
+ ClientResponse clientResponse = prepareClientResponse(body, httpHeaders);
+ Mono<byte[]> modifiedBody = clientResponse.bodyToMono(byte[].class)
+ .flatMap(originalBody -> Mono.just(updateResponse(originalBody)));
+
+ BodyInserter<Mono<byte[]>, ReactiveHttpOutputMessage> bodyInserter =
+ BodyInserters.fromPublisher(modifiedBody, byte[].class);
+ CachedBodyOutputMessage outputMessage = new CachedBodyOutputMessage(exchange,
+ exchange.getResponse().getHeaders());
+ return bodyInserter.insert(outputMessage, new BodyInserterContext()).then(Mono.defer(() -> {
+ Mono<DataBuffer> messageBody = DataBufferUtils.join(outputMessage.getBody());
+ HttpHeaders headers = getDelegate().getHeaders();
+ if (!headers.containsKey(HttpHeaders.TRANSFER_ENCODING)
+ || headers.containsKey(HttpHeaders.CONTENT_LENGTH)) {
+ messageBody = messageBody.doOnNext(data -> headers.setContentLength(data.readableByteCount()));
+ }
+ return getDelegate().writeWith(messageBody);
+ }));
+
+ }
+
+ private byte[] updateResponse(final byte[] responseBody) {
+ if (Objects.isNull(handle)) {
+ return responseBody;
+ }
+
+ String bodyStr = operation(new String(responseBody, StandardCharsets.UTF_8), handle);
+ return bodyStr.getBytes(StandardCharsets.UTF_8);
+ }
+
+ private String operation(final String jsonValue, final ModifyResponseRuleHandle handle) {
+ DocumentContext context = JsonPath.parse(jsonValue);
+ operation(context, handle);
+ if (!CollectionUtils.isEmpty(handle.getReplaceBodyKeys())) {
+ handle.getReplaceBodyKeys().forEach(info -> {
+ context.renameKey(info.getPath(), info.getKey(), info.getValue());
+ });
+ }
+ if (!CollectionUtils.isEmpty(handle.getRemoveBodyKeys())) {
+ handle.getRemoveBodyKeys().forEach(info -> {
+ context.delete(info);
+ });
+ }
+ return context.jsonString();
+ }
+
+ private void operation(final DocumentContext context, final ModifyResponseRuleHandle handle) {
+ if (!CollectionUtils.isEmpty(handle.getAddBodyKeys())) {
+ handle.getAddBodyKeys().forEach(info -> {
+ context.put(info.getPath(), info.getKey(), info.getValue());
+ });
+ }
+ }
+
+ private ClientResponse prepareClientResponse(final Publisher<? extends DataBuffer> body, final HttpHeaders httpHeaders) {
+ ClientResponse.Builder builder;
+ builder = ClientResponse.create(exchange.getResponse().getStatusCode(), ServerCodecConfigurer.create().getReaders());
+ return builder.headers(headers -> headers.putAll(httpHeaders)).body(Flux.from(body)).build();
+ }
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/cache/ModifyResponseRuleHandleCache.java b/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/cache/ModifyResponseRuleHandleCache.java
new file mode 100644
index 0000000..56f4634
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/cache/ModifyResponseRuleHandleCache.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+package org.apache.shenyu.plugin.response.cache;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shenyu.common.dto.convert.rule.impl.ModifyResponseRuleHandle;
+import org.apache.shenyu.plugin.base.cache.BaseHandleCache;
+
+/**
+ * The rule handle cache.
+ */
+@SuppressWarnings("all")
+@Slf4j
+public final class ModifyResponseRuleHandleCache extends BaseHandleCache<String, ModifyResponseRuleHandle> {
+
+ private ModifyResponseRuleHandleCache() {
+ }
+
+ /**
+ * Gets instance.
+ *
+ * @return the instance
+ */
+ public static ModifyResponseRuleHandleCache getInstance() {
+ return ModifyResponseRuleHandleCacheInstance.INSTANCE;
+ }
+
+ /**
+ * The type rule handle cache instance.
+ */
+ static class ModifyResponseRuleHandleCacheInstance {
+ /**
+ * The Instance.
+ */
+ static final ModifyResponseRuleHandleCache INSTANCE = new ModifyResponseRuleHandleCache();
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/handler/ModifyResponsePluginDataHandler.java b/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/handler/ModifyResponsePluginDataHandler.java
new file mode 100644
index 0000000..483b4e4
--- /dev/null
+++ b/shenyu-plugin/shenyu-plugin-modify-response/src/main/java/org/apache/shenyu/plugin/response/handler/ModifyResponsePluginDataHandler.java
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+
+package org.apache.shenyu.plugin.response.handler;
+
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.convert.rule.impl.ModifyResponseRuleHandle;
+import org.apache.shenyu.common.enums.PluginEnum;
+import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.apache.shenyu.plugin.response.cache.ModifyResponseRuleHandleCache;
+
+import java.util.Optional;
+
+/**
+ * ModifyResponse rule handle.
+ */
+public class ModifyResponsePluginDataHandler implements PluginDataHandler {
+
+ @Override
+ public void handlerRule(final RuleData ruleData) {
+ Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> {
+ final ModifyResponseRuleHandle modifyResponseRuleHandle = GsonUtils.getInstance().fromJson(s, ModifyResponseRuleHandle.class);
+ ModifyResponseRuleHandleCache.getInstance().cachedHandle(getResourceName(ruleData), modifyResponseRuleHandle);
+ });
+ }
+
+ @Override
+ public void removeRule(final RuleData ruleData) {
+ Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> {
+ ModifyResponseRuleHandleCache.getInstance().removeHandle(getResourceName(ruleData));
+ });
+ }
+
+ @Override
+ public String pluginNamed() {
+ return PluginEnum.MODIFY_RESPONSE.getName();
+ }
+
+ /**
+ * Resource name.
+ *
+ * @param ruleData the ruleData
+ * @return String
+ */
+ public static String getResourceName(final RuleData ruleData) {
+ return ruleData.getSelectorId() + "_" + ruleData.getName();
+ }
+}
diff --git a/shenyu-plugin/shenyu-plugin-response/src/main/java/org/apache/shenyu/plugin/response/strategy/WebClientMessageWriter.java b/shenyu-plugin/shenyu-plugin-response/src/main/java/org/apache/shenyu/plugin/response/strategy/WebClientMessageWriter.java
index a10a225..b26943a 100644
--- a/shenyu-plugin/shenyu-plugin-response/src/main/java/org/apache/shenyu/plugin/response/strategy/WebClientMessageWriter.java
+++ b/shenyu-plugin/shenyu-plugin-response/src/main/java/org/apache/shenyu/plugin/response/strategy/WebClientMessageWriter.java
@@ -51,7 +51,6 @@ public class WebClientMessageWriter implements MessageWriter {
Object error = ShenyuResultWrap.error(ShenyuResultEnum.SERVICE_TIMEOUT.getCode(), ShenyuResultEnum.SERVICE_TIMEOUT.getMsg(), null);
return WebFluxResultUtils.result(exchange, error);
}
- response.setStatusCode(clientResponse.statusCode());
response.getCookies().putAll(clientResponse.cookies());
response.getHeaders().putAll(clientResponse.headers().asHttpHeaders());
return response.writeWith(clientResponse.body(BodyExtractors.toDataBuffers())).doOnCancel(() -> clean(exchange));
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/pom.xml
index ab6c978..e3beafd 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/pom.xml
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/pom.xml
@@ -51,6 +51,7 @@
<module>shenyu-spring-boot-starter-plugin-grpc</module>
<module>shenyu-spring-boot-starter-plugin-redirect</module>
<module>shenyu-spring-boot-starter-plugin-logging</module>
+ <module>shenyu-spring-boot-starter-plugin-modify-response</module>
<module>shenyu-spring-boot-starter-plugin-request</module>
<module>shenyu-spring-boot-starter-plugin-oauth2</module>
<module>shenyu-spring-boot-starter-plugin-jwt</module>
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/pom.xml b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/pom.xml
new file mode 100644
index 0000000..aeda5b2
--- /dev/null
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/pom.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-spring-boot-starter-plugin</artifactId>
+ <version>2.4.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>shenyu-spring-boot-starter-plugin-modify-response</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-plugin-modify-response</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/java/org/apache/shenyu/springboot/starter/plugin/modifyresponse/ModifyResponsePluginConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/java/org/apache/shenyu/springboot/starter/plugin/modifyresponse/ModifyResponsePluginConfiguration.java
new file mode 100644
index 0000000..180ab42
--- /dev/null
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/java/org/apache/shenyu/springboot/starter/plugin/modifyresponse/ModifyResponsePluginConfiguration.java
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+package org.apache.shenyu.springboot.starter.plugin.modifyresponse;
+
+import org.apache.shenyu.plugin.api.ShenyuPlugin;
+import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
+import org.apache.shenyu.plugin.response.ModifyResponsePlugin;
+import org.apache.shenyu.plugin.response.handler.ModifyResponsePluginDataHandler;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * The type ModifyResponse plugin configuration.
+ */
+@Configuration
+public class ModifyResponsePluginConfiguration {
+
+ /**
+ * ModifyResponse plugin.
+ *
+ * @return the soul plugin
+ */
+ @Bean
+ public ShenyuPlugin modifyResponsePlugin() {
+ return new ModifyResponsePlugin();
+ }
+
+ /**
+ * ModifyResponse plugin data handler.
+ *
+ * @return the plugin data handler
+ */
+ @Bean
+ public PluginDataHandler responsePluginDataHandler() {
+ return new ModifyResponsePluginDataHandler();
+ }
+}
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/resources/META-INF/spring.factories b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..a980c69
--- /dev/null
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.shenyu.springboot.starter.plugin.modifyresponse.ModifyResponsePluginConfiguration
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/resources/META-INF/spring.provides b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/resources/META-INF/spring.provides
new file mode 100644
index 0000000..32fab4f
--- /dev/null
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-modify-response/src/main/resources/META-INF/spring.provides
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+provides: shenyu-spring-boot-starter-plugin-modify-response