Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove duplicate Content-Type header in error cases
Prior to this commit, the `DispatcherServlet` would try and reset the response buffer in case of errors, if the response is not committed already. This allows for more flexible error handling, even if the response was being handled already when it errored. Resetting the response buffer clears the body but leaves HTTP response headers intact. This is done on purpose as to not clear headers previously added by Servlet Filters. By leaving in place some headers like "Content-Type", this does not take into account the fact that the response body was cleared and that error handling will perform another round of content negotiation. While this isn't a problem for some Servlet containers which enforce a single "Content-Type" header value, this can cause multiple/duplicate values for some others. This commit ensures that the "Content-Type" response header is removed at the same time as we clear the "producible media types" attribute: another pass of content negotiation will be performed for error handling. Fixes gh-34366
- Loading branch information