Skip to content

Commit

Permalink
Avoid setting special Content-* response headers for Tomcat
Browse files Browse the repository at this point in the history
As of gh-21783, Spring WebFlux uses a `TomcatHeadersAdapter`
implementation to directly address the native headers used by the
server.

In the case of Tomcat, "Content-Length" and "Content-Type" headers are
processed separately and should not be added to the native headers map.

This commit improves the `HandlerAdapter` implementation for Tomcat and
removes those headers, if previously set in the map. The adapter
already has a section that handles the Tomcat-specific calls for such
headers.

Fixes gh-24361
  • Loading branch information
bclozel committed Jan 17, 2020
1 parent daa30a9 commit 59bef22
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ protected void applyHeaders() {
if (response.getContentType() == null && contentType != null) {
response.setContentType(contentType.toString());
}
getHeaders().remove(HttpHeaders.CONTENT_TYPE);
Charset charset = (contentType != null ? contentType.getCharset() : null);
if (response.getCharacterEncoding() == null && charset != null) {
response.setCharacterEncoding(charset.name());
Expand All @@ -224,6 +225,7 @@ protected void applyHeaders() {
if (contentLength != -1) {
response.setContentLengthLong(contentLength);
}
getHeaders().remove(HttpHeaders.CONTENT_LENGTH);
}

@Override
Expand Down

0 comments on commit 59bef22

Please sign in to comment.