-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Closed
Closed
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug
Milestone
Description
Brian Clozel opened SPR-17082 and commented
The current implementation of the ResponseEntityResultHandler
only writes each ResponseEntity
response header on the response only if there's none already for that header name.
This behavior is not consistent with what's being done in Spring MVC with the HttpEntityMethodProcessor
- it also creates issues for some use cases (see reference URL for an example).
Given the following code snippet:
@GetMapping(path="/test", produces="text/plain")
@ResponseBody
public Mono<String> handler() {
return Mono.error(new IllegalArgumentException("error"));
}
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<String> errorhandler(IllegalArgumentException ex) {
return ResponseEntity.badRequest()
.contentType(MediaType.APPLICATION_JSON)
.body(jsonBody);
}
In such a case, here's what happens:
- the handler is selected and invoked
- the text/plain content-type handler is written to the response
- it's getting an error signal instead of the response body
- the exception handler is invoked, all response entity headers are applied to the response, expect the ones that are already present in the response
- Content-Type is already there, so it's not written and the client will get an HTTP 406 instead
Affects: 5.0.7
Reference URL: spring-projects/spring-boot#13635
Issue Links:
- Cannot overwrite content-type response header with WebFlux [SPR-17415] #21948 Cannot overwrite content-type response header with WebFlux
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug