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 spring-projectsgh-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 spring-projectsgh-24387
  • Loading branch information
bclozel committed Jan 17, 2020
1 parent 6699833 commit e1e8c16
Showing 1 changed file with 2 additions and 0 deletions.
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 e1e8c16

Please sign in to comment.