Skip to content

Commit 59bef22

Browse files
committed
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-24361
1 parent daa30a9 commit 59bef22

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHttpHandlerAdapter.java

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ protected void applyHeaders() {
216216
if (response.getContentType() == null && contentType != null) {
217217
response.setContentType(contentType.toString());
218218
}
219+
getHeaders().remove(HttpHeaders.CONTENT_TYPE);
219220
Charset charset = (contentType != null ? contentType.getCharset() : null);
220221
if (response.getCharacterEncoding() == null && charset != null) {
221222
response.setCharacterEncoding(charset.name());
@@ -224,6 +225,7 @@ protected void applyHeaders() {
224225
if (contentLength != -1) {
225226
response.setContentLengthLong(contentLength);
226227
}
228+
getHeaders().remove(HttpHeaders.CONTENT_LENGTH);
227229
}
228230

229231
@Override

0 commit comments

Comments
 (0)