Set content length on ServletHttpResponse
Prior to this commit, the `ServletServerHttpResponse` would copy headers from the `HttpHeaders` map and calls methods related to headers exposed as properties (content-type, character encoding). Unlike its reactive variant, this would not set the content length. Depending on the Servlet container implementation, this could cause duplicate Content-Length response headers in the actual HTTP response. This commit aligns both implementations and ensures that the `setContentLengthLong` method is called if necessary so that the Servlet container can ensure a single header for that. Fixes gh-26330
This commit is contained in:
@@ -125,6 +125,10 @@ public class ServletServerHttpResponse implements ServerHttpResponse {
|
|||||||
this.headers.getContentType().getCharset() != null) {
|
this.headers.getContentType().getCharset() != null) {
|
||||||
this.servletResponse.setCharacterEncoding(this.headers.getContentType().getCharset().name());
|
this.servletResponse.setCharacterEncoding(this.headers.getContentType().getCharset().name());
|
||||||
}
|
}
|
||||||
|
long contentLength = getHeaders().getContentLength();
|
||||||
|
if (contentLength != -1) {
|
||||||
|
this.servletResponse.setContentLengthLong(contentLength);
|
||||||
|
}
|
||||||
this.headersWritten = true;
|
this.headersWritten = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user