Merge remote-tracking branch 'origin/2.0.x' into 2.1.x
This commit is contained in:
@@ -49,20 +49,22 @@ public class WebClientWriteResponseFilter implements GlobalFilter, Ordered {
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
// NOTICE: nothing in "pre" filter stage as CLIENT_RESPONSE_ATTR is not added
|
||||
// until the WebHandler is run
|
||||
return chain.filter(exchange)
|
||||
.doOnError(throwable -> cleanup(exchange))
|
||||
return chain.filter(exchange).doOnError(throwable -> cleanup(exchange))
|
||||
.then(Mono.defer(() -> {
|
||||
ClientResponse clientResponse = exchange.getAttribute(CLIENT_RESPONSE_ATTR);
|
||||
if (clientResponse == null) {
|
||||
return Mono.empty();
|
||||
}
|
||||
log.trace("WebClientWriteResponseFilter start");
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
ClientResponse clientResponse = exchange
|
||||
.getAttribute(CLIENT_RESPONSE_ATTR);
|
||||
if (clientResponse == null) {
|
||||
return Mono.empty();
|
||||
}
|
||||
log.trace("WebClientWriteResponseFilter start");
|
||||
ServerHttpResponse response = exchange.getResponse();
|
||||
|
||||
return response.writeWith(clientResponse.body(BodyExtractors.toDataBuffers()))
|
||||
//.log("webClient response")
|
||||
.doOnCancel(() -> cleanup(exchange));
|
||||
}));
|
||||
return response
|
||||
.writeWith(
|
||||
clientResponse.body(BodyExtractors.toDataBuffers()))
|
||||
// .log("webClient response")
|
||||
.doOnCancel(() -> cleanup(exchange));
|
||||
}));
|
||||
}
|
||||
|
||||
private void cleanup(ServerWebExchange exchange) {
|
||||
@@ -71,4 +73,5 @@ public class WebClientWriteResponseFilter implements GlobalFilter, Ordered {
|
||||
clientResponse.bodyToMono(Void.class).subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -154,8 +154,7 @@ public class ModifyResponseBodyGatewayFilterFactory extends
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ServerHttpResponse decorate(ServerWebExchange exchange) {
|
||||
return new ServerHttpResponseDecorator(
|
||||
exchange.getResponse()) {
|
||||
return new ServerHttpResponseDecorator(exchange.getResponse()) {
|
||||
|
||||
@Override
|
||||
public Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
|
||||
|
||||
@@ -247,6 +247,29 @@ public class GatewayFilterSpec extends UriSpec {
|
||||
.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.
|
||||
@@ -287,6 +310,28 @@ public class GatewayFilterSpec extends UriSpec {
|
||||
.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.
|
||||
|
||||
Reference in New Issue
Block a user