Description
Some servlet containers (at least Undertow and Tomcat) allow clearing a previously set character encoding by calling response.setCharacterEncoding(null)
. This is useful when CharacterEncodingFilter
is used, but some handlers need to deliver binary data without the charset
clause in the Content-Type
response header.
Code doing that cannot currently be tested with MockMvc, because MockHttpServletResponse.setCharacterEncoding(null)
throws an IllegalArgumentException
.
The Javadoc of the Servlet API in JakartaEE has been updated a while ago to support null
there: jakartaee/servlet@22c8f34
The JakartaEE guys were quite unanimous about the subject: jakartaee/servlet#377
MockHttpServletResponse.setCharacterEncoding(null)
should clear any character encoding previously set on the response.