Keep the space after semicolon in Content-type header response using tomcat

左心房为你撑大大i 提交于 2019-12-12 12:19:16

问题


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.


回答1:


As is posted in the comments, this is something that we cannot avoid as it's hardcoded in the tomcat source code

In our particular use case, we finally have been able to change a little bit the legacy-client, so now it can process the content type header in the standard format (without space).

Thanks @zack6849 por pointing that.



来源:https://stackoverflow.com/questions/49409116/keep-the-space-after-semicolon-in-content-type-header-response-using-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!