We have a legacy client consuming a servlet deployed on tomcat 8.5. This legacy client is waiting for the content-type header response in this format (note the whitespace between the semicolon and 'charset'):
Content-type: text/xml; charset=utf-8
However, in the server side, Tomcat is always trimming this whitespace, althought we force it in the servlet:
response.setContentType("text/xml; charset=utf-8");
Or even in a filter with a custom extension of HttpServletResponseWrapper
, as suggested in this question.
Whatever I try, the content-type header is always returned without the whitespace.
Content-type: text/xml;charset=utf-8
As a reference, I found this in the tomcat official documentation:
Tomcat removes blank chars between the ';' and the 'charset' keyword
I know the http standard says that the whitespace is optional after the semicolon, as mentioned in this other SO post but as the client with the problem runs a legacy version, I'm wondering if there is any way to force tomcat to keep this whitespace.
I'm thinking about other choices such as modifying the content-type header in apache or nginx (above tomcat), but if it's possible I would prefer a solution at tomcat level.
Any help would be appreciated.