Browse Source

Merge pull request #1093 from re6exp/2.0.x

Add methods using custom spec to GatewayFilterSpec::modifyResponseBody() and GatewayFilterSpec::modifyRequestBody()
2.0.x
Ryan Baxter 6 years ago committed by GitHub
parent
commit
9e2c7fedf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 46
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java

46
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java

@ -235,6 +235,30 @@ public class GatewayFilterSpec extends UriSpec { @@ -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
* <pre>
* {@code
* ...
* .modifyRequestBody(c -> c
* .setInClass(Some.class)
* .setOutClass(SomeOther.class)
* .setInHints(hintsIn)
* .setOutHints(hintsOut)
* .setRewriteFunction(rewriteFunction))
* }
* </pre>
*/
public <T, R> GatewayFilterSpec modifyRequestBody(
Consumer<ModifyRequestBodyGatewayFilterFactory.Config> 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 { @@ -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
* <pre>
* {@code
* ...
* .modifyResponseBody(c -> c
* .setInClass(Some.class)
* .setOutClass(SomeOther.class)
* .setOutHints(hintsOut)
* .setRewriteFunction(rewriteFunction))
* }
* </pre>
*/
public <T, R> GatewayFilterSpec modifyResponseBody(
Consumer<ModifyResponseBodyGatewayFilterFactory.Config> 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.

Loading…
Cancel
Save