Bug 61916

Summary: AddDefaultCharsetFilter wouldn't work when setting response header through response.setHeader()
Product: Tomcat 8 Reporter: Fuwei Chin <fuweichin>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 8.5.23   
Target Milestone: ----   
Hardware: PC   
OS: All   

Description Fuwei Chin 2017-12-19 06:34:20 UTC
AddDefaultCharsetFilter wouldn't work if one set response header 'content-type' through setHeader() instead of setContentType().
I tried to debug the webapp by adding a breakpoint in be beginning of method AddDefaultCharsetFilter.ResponseWrapper#setContentType(String), while the CXF framework did't invoke setContentType().
So I think that cxf may set response header Content-Type by invoking setHeader() but there is not a overridden method setHeader() in class AddDefaultCharsetFilter.ResponseWrapper

Steps to Reproduce:
1) Adding a maven dependecy in pom.xml
2) Adding a filter registeration in web.xml
3) Adding a method in cxf jax-rs service bean UserResource.java
public Response hello(){
	return Response.ok("hello").build();
4) request the hello service

Actual Results:
Content-Type: text/plain

Expected Results:
Content-Type: text/plain;charset=UTF-8

Build Date & Hardware:
Additional Builds and Platforms:

Additional Information:
Comment 1 Mark Thomas 2018-01-04 17:32:51 UTC
Thanks for the report. I fixed addHeader() as well as setHeader()

Fixed in:
- trunk for 9.0.3 onwards
- 8.5.x for 8.5.25 onwards
- 8.0.x for 8.0.49 onwards
- 7.0.x for 7.0.84 onwards
Comment 2 Konstantin Kolinko 2018-01-16 17:31:20 UTC
Implementation of addHeader() in r1820138 is broken: it needs to call super.addHeader().

This concerns 9.0.3 (currently being voted as a release candidate).

A fix is trivial, but maybe it is worth to extend the unit tests that were created for this issue.
Comment 3 Mark Thomas 2018-01-16 22:33:49 UTC
Regression fixed in:
- trunk for 9.0.4 onwards
- 8.5.x for 8.5.27 onwards
- 8.0.x for 8.0.49 onwards
- 7.0.x for 7.0.84 onwards