This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 8262f498d5 fix(request): support partial mutation configurations
(#6507) (#7631)
8262f498d5 is described below
commit 8262f498d5558e03cefa6997cff8cd1b7ba33552
Author: JerryčAI <[email protected]>
AuthorDate: Thu Oct 15 14:06:49 2026 +0800
fix(request): support partial mutation configurations (#6507) (#7631)
Signed-off-by: jerry <[email protected]>
---
.../common/dto/convert/rule/RequestHandle.java | 4 ++-
.../common/dto/convert/rule/RequestHandleTest.java | 37 ++++++++++++++++++++++
.../shenyu/plugin/request/RequestPluginTest.java | 28 ++++++++++++++++
3 files changed, 68 insertions(+), 1 deletion(-)
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/RequestHandle.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/RequestHandle.java
index 90fb54f72d..feb98a7962 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/RequestHandle.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/convert/rule/RequestHandle.java
@@ -234,7 +234,9 @@ public class RequestHandle {
* @return not empty is true
*/
private boolean isNotEmptyConfig() {
- return header.isNotEmptyConfig() || parameter.isNotEmptyConfig() ||
cookie.isNotEmptyConfig();
+ return Objects.nonNull(header) && header.isNotEmptyConfig()
+ || Objects.nonNull(parameter) && parameter.isNotEmptyConfig()
+ || Objects.nonNull(cookie) && cookie.isNotEmptyConfig();
}
public class ShenyuRequestHeader {
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/rule/RequestHandleTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/rule/RequestHandleTest.java
index d2d6c20a47..4e4ef0e6a9 100644
---
a/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/rule/RequestHandleTest.java
+++
b/shenyu-common/src/test/java/org/apache/shenyu/common/dto/convert/rule/RequestHandleTest.java
@@ -71,6 +71,43 @@ public class RequestHandleTest {
assertThat(handle.isEmptyConfig(), is(true));
}
+ @Test
+ public void testMissingSectionsAreEmpty() {
+ RequestHandle handle = new RequestHandle();
+ assertThat(handle.isEmptyConfig(), is(true));
+ handle.setHeader(handle.new ShenyuRequestHeader());
+ assertThat(handle.isEmptyConfig(), is(true));
+ handle.setParameter(handle.new ShenyuRequestParameter());
+ assertThat(handle.isEmptyConfig(), is(true));
+ }
+
+ @Test
+ public void testParameterOnlyConfig() {
+ RequestHandle handle = new RequestHandle();
+ RequestHandle.ShenyuRequestParameter parameter = handle.new
ShenyuRequestParameter();
+ parameter.setAddParameters(ImmutableMap.of("key", "value"));
+ handle.setParameter(parameter);
+ assertThat(handle.isEmptyConfig(), is(false));
+ }
+
+ @Test
+ public void testCookieOnlyConfig() {
+ RequestHandle handle = new RequestHandle();
+ RequestHandle.ShenyuCookie cookie = handle.new ShenyuCookie();
+ cookie.setAddCookies(ImmutableMap.of("key", "value"));
+ handle.setCookie(cookie);
+ assertThat(handle.isEmptyConfig(), is(false));
+ }
+
+ @Test
+ public void testHeaderOnlyConfig() {
+ RequestHandle handle = new RequestHandle();
+ RequestHandle.ShenyuRequestHeader header = handle.new
ShenyuRequestHeader();
+ header.setAddHeaders(ImmutableMap.of("key", "value"));
+ handle.setHeader(header);
+ assertThat(handle.isEmptyConfig(), is(false));
+ }
+
@Test
public void testShenyuRequestHeader() {
RequestHandle handle = new RequestHandle();
diff --git
a/shenyu-plugin/shenyu-plugin-request/src/test/java/org/apache/shenyu/plugin/request/RequestPluginTest.java
b/shenyu-plugin/shenyu-plugin-request/src/test/java/org/apache/shenyu/plugin/request/RequestPluginTest.java
index 173a4056c8..199f68331b 100644
---
a/shenyu-plugin/shenyu-plugin-request/src/test/java/org/apache/shenyu/plugin/request/RequestPluginTest.java
+++
b/shenyu-plugin/shenyu-plugin-request/src/test/java/org/apache/shenyu/plugin/request/RequestPluginTest.java
@@ -122,6 +122,34 @@ public class RequestPluginTest {
RequestPluginHandler.CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(this.ruleData),
requestHandle);
}
+ @Test
+ public void testParameterOnlyRule() {
+
ruleData.setHandle("{\"parameter\":{\"addParameters\":{\"partial\":\"value\"}}}");
+ new RequestPluginHandler().handlerRule(ruleData);
+ when(chain.execute(any())).thenReturn(Mono.empty());
+
+ StepVerifier.create(requestPlugin.doExecute(exchange, chain, new
SelectorData(), ruleData)).verifyComplete();
+
+ ArgumentCaptor<ServerWebExchange> captor =
ArgumentCaptor.forClass(ServerWebExchange.class);
+ Mockito.verify(chain).execute(captor.capture());
+ assertEquals("value",
captor.getValue().getRequest().getQueryParams().getFirst("partial"));
+ assertEquals("oldValue",
captor.getValue().getRequest().getHeaders().getFirst("addKey"));
+ }
+
+ @Test
+ public void testCookieOnlyRule() {
+
ruleData.setHandle("{\"cookie\":{\"addCookies\":{\"partial\":\"value\"}}}");
+ new RequestPluginHandler().handlerRule(ruleData);
+ when(chain.execute(any())).thenReturn(Mono.empty());
+
+ StepVerifier.create(requestPlugin.doExecute(exchange, chain, new
SelectorData(), ruleData)).verifyComplete();
+
+ ArgumentCaptor<ServerWebExchange> captor =
ArgumentCaptor.forClass(ServerWebExchange.class);
+ Mockito.verify(chain).execute(captor.capture());
+
assertTrue(captor.getValue().getRequest().getHeaders().getFirst(HttpHeaders.COOKIE).contains("partial=value"));
+ assertEquals("oldValue",
captor.getValue().getRequest().getQueryParams().getFirst("addKey"));
+ }
+
@Test
public void testResponseDedupDoesNotRequireRequestStrategy() {
RequestHandle handle =
RequestPluginHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(ruleData));