Consistent adaptation of HTTP headers on Servlet responses
Spring comes with various Servlet response wrappers that adapt specific headers to the HttpServletResponse, in particular to setContentLength and setCharacterEncoding where the Servlet response may hold a local setting that is not fully in synch with the corresponding HTTP headers (either in the Servlet container itself or in a Servlet response decorator applied by a Filter).
There is a key improvement that we can consistently apply: lazily and defensively parsing the content type, under the assumption that this adaptation code is usually not kicking in, therefore avoiding any unnecessary overhead in the common path. As a side topic, we can also use the new setCharacterEncoding(Charset) method on Servlet 6.1 now, avoiding unnecessary Charset->String->Charset transformations.