From e1e8c165db8d1866d11ed4e51b5abfb7240024cd Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 17 Jan 2020 15:01:58 +0100 Subject: [PATCH] Avoid setting special Content-* response headers for Tomcat 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-24387 --- .../http/server/reactive/TomcatHttpHandlerAdapter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHttpHandlerAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHttpHandlerAdapter.java index 055869ed0bbe..c01a11b5a7ef 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHttpHandlerAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHttpHandlerAdapter.java @@ -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()); @@ -224,6 +225,7 @@ protected void applyHeaders() { if (contentLength != -1) { response.setContentLengthLong(contentLength); } + getHeaders().remove(HttpHeaders.CONTENT_LENGTH); } @Override