Skip to content

Support setCharacterEncoding(null) in MockHttpServletResponse #30341

Closed
@chschu

Description

@chschu

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.

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions