Browse Source

Polishing in ResponseEntityResultHandler

See gh-files
pull/29918/head
divcon 3 years ago committed by rstoyanchev
parent
commit
09991f2492
  1. 15
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java

15
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java

@ -150,8 +150,8 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand @@ -150,8 +150,8 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand
httpEntity = new ResponseEntity<>(headers, HttpStatus.OK);
}
else {
throw new IllegalArgumentException(
"HttpEntity or HttpHeaders expected but got: " + returnValue.getClass());
return Mono.error(() -> new IllegalArgumentException(
"HttpEntity or HttpHeaders expected but got: " + returnValue.getClass()));
}
if (httpEntity.getBody() instanceof ProblemDetail detail) {
@ -175,8 +175,7 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand @@ -175,8 +175,7 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand
HttpHeaders entityHeaders = httpEntity.getHeaders();
HttpHeaders responseHeaders = exchange.getResponse().getHeaders();
if (!entityHeaders.isEmpty()) {
entityHeaders.entrySet().stream()
.forEach(entry -> responseHeaders.put(entry.getKey(), entry.getValue()));
responseHeaders.putAll(entityHeaders);
}
if (httpEntity.getBody() == null || returnValue instanceof HttpHeaders) {
@ -186,11 +185,9 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand @@ -186,11 +185,9 @@ public class ResponseEntityResultHandler extends AbstractMessageWriterResultHand
String etag = entityHeaders.getETag();
Instant lastModified = Instant.ofEpochMilli(entityHeaders.getLastModified());
HttpMethod httpMethod = exchange.getRequest().getMethod();
if (SAFE_METHODS.contains(httpMethod) && exchange.checkNotModified(etag, lastModified)) {
return exchange.getResponse().setComplete();
}
return writeBody(httpEntity.getBody(), bodyParameter, actualParameter, exchange);
return (SAFE_METHODS.contains(httpMethod) && exchange.checkNotModified(etag, lastModified)) ?
exchange.getResponse().setComplete()
: writeBody(httpEntity.getBody(), bodyParameter, actualParameter, exchange);
});
}

Loading…
Cancel
Save