diff --git a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java index 037b83afd..9247125b1 100644 --- a/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java +++ b/spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java @@ -235,6 +235,30 @@ public class GatewayFilterSpec extends UriSpec { return filter(getBean(ModifyRequestBodyGatewayFilterFactory.class) .apply(c -> c.setRewriteFunction(inClass, outClass, rewriteFunction).setContentType(newContentType))); } + + /** + * A filter that can be used to modify the request body. This filter is BETA and may + * be subject to change in a future release. + * @param configConsumer request spec for response modification + * @return a {@link GatewayFilterSpec} that can be used to apply additional filters + *
+	 * {@code
+	 * ...
+	 * .modifyRequestBody(c -> c
+	 *		.setInClass(Some.class)
+	 *		.setOutClass(SomeOther.class)
+ 	 *		.setInHints(hintsIn)
+	 *		.setOutHints(hintsOut)
+	 *		.setRewriteFunction(rewriteFunction))
+	 * }
+	 * 
+ */ + public GatewayFilterSpec modifyRequestBody( + Consumer configConsumer) { + return filter(getBean(ModifyRequestBodyGatewayFilterFactory.class) + .apply(configConsumer)); + } + /** * A filter that can be used to modify the response body * This filter is BETA and may be subject to change in a future release. @@ -266,6 +290,28 @@ public class GatewayFilterSpec extends UriSpec { return filter(getBean(ModifyResponseBodyGatewayFilterFactory.class) .apply(c -> c.setRewriteFunction(inClass, outClass, rewriteFunction).setNewContentType(newContentType))); } + + /** + * A filter that can be used to modify the response body using custom spec. + * This filter is BETA and may be subject to change in a future release. + * @param configConsumer response spec for response modification + * @return a {@link GatewayFilterSpec} that can be used to apply additional filters + *
+	 * {@code
+	 * ...
+	 * .modifyResponseBody(c -> c
+	 *		.setInClass(Some.class)
+	 *		.setOutClass(SomeOther.class)
+	 *		.setOutHints(hintsOut)
+	 *		.setRewriteFunction(rewriteFunction))
+	 * }
+	 * 
+ */ + public GatewayFilterSpec modifyResponseBody( + Consumer configConsumer) { + return filter(getBean(ModifyResponseBodyGatewayFilterFactory.class) + .apply(configConsumer)); + } /** * A filter that can be used to add a prefix to the path of a request before it is routed by the Gateway.