Browse Source

Remove unnecessary exception creation when Creating a CachedBodyOutputMessage.

Fixes gh-2888
pull/2918/head
koo.taejin 2 years ago committed by spencergibb
parent
commit
b31af9eef0
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 6
      spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/CachedBodyOutputMessage.java

6
spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/factory/rewrite/CachedBodyOutputMessage.java

@ -40,8 +40,7 @@ public class CachedBodyOutputMessage implements ReactiveHttpOutputMessage { @@ -40,8 +40,7 @@ public class CachedBodyOutputMessage implements ReactiveHttpOutputMessage {
private boolean cached = false;
private Flux<DataBuffer> body = Flux
.error(new IllegalStateException("The body is not set. " + "Did handling complete with success?"));
private Flux<DataBuffer> body = null;
public CachedBodyOutputMessage(ServerWebExchange exchange, HttpHeaders httpHeaders) {
this.bufferFactory = exchange.getResponse().bufferFactory();
@ -77,6 +76,9 @@ public class CachedBodyOutputMessage implements ReactiveHttpOutputMessage { @@ -77,6 +76,9 @@ public class CachedBodyOutputMessage implements ReactiveHttpOutputMessage {
* @return body as {@link Flux}
*/
public Flux<DataBuffer> getBody() {
if (body == null) {
return Flux.error(new IllegalStateException("The body is not set. " + "Did handling complete with success?"));
}
return this.body;
}

Loading…
Cancel
Save