Skip to content

Commit fb66619

Browse files
committed
Merge branch '5.1.x'
2 parents 25d7f09 + e47f7ef commit fb66619

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.context.ApplicationContextAware;
3030
import org.springframework.context.ConfigurableApplicationContext;
3131
import org.springframework.core.ReactiveAdapterRegistry;
32+
import org.springframework.http.HttpHeaders;
3233
import org.springframework.http.codec.HttpMessageReader;
3334
import org.springframework.http.codec.ServerCodecConfigurer;
3435
import org.springframework.lang.Nullable;
@@ -209,6 +210,9 @@ private Mono<HandlerResult> handleException(Throwable exception, HandlerMethod h
209210

210211
// Success and error responses may use different content types
211212
exchange.getAttributes().remove(HandlerMapping.PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE);
213+
if (!exchange.getResponse().isCommitted()) {
214+
exchange.getResponse().getHeaders().remove(HttpHeaders.CONTENT_TYPE);
215+
}
212216

213217
InvocableHandlerMethod invocable = this.methodResolver.getExceptionHandlerMethod(exception, handlerMethod);
214218
if (invocable != null) {

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingExceptionHandlingIntegrationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void exceptionAfterSeveralItems() {
9393
public void exceptionFromMethodWithProducesCondition() throws Exception {
9494
try {
9595
HttpHeaders headers = new HttpHeaders();
96-
headers.add("Accept", "text/csv, application/problem+json");
96+
headers.add("Accept", "text/plain, application/problem+json");
9797
performGet("/SPR-16318", headers, String.class).getBody();
9898
fail();
9999
}
@@ -152,9 +152,9 @@ public Flux<String> errors() {
152152
});
153153
}
154154

155-
@GetMapping(path = "/SPR-16318", produces = "text/csv")
156-
public String handleCsv() throws Exception {
157-
throw new Spr16318Exception();
155+
@GetMapping(path = "/SPR-16318", produces = "text/plain")
156+
public Mono<String> handleTextPlain() throws Exception {
157+
return Mono.error(new Spr16318Exception());
158158
}
159159

160160
@ExceptionHandler

0 commit comments

Comments
 (0)