使用tomcat在Content-type头响应中以分号保留空格 [英] Keep the space after semicolon in Content-type header response using tomcat

查看:697
本文介绍了使用tomcat在Content-type头响应中以分号保留空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个传统客户端消耗部署在tomcat 8.5上的servlet。
这个遗留客户端正在等待这种格式的内容类型标头响应(请注意分号和'charset'之间的空格):

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

然而,在服务器端,Tomcat总是修剪这个空白,尽管我们强制它在servlet中:

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");

甚至在自定义扩展名 HttpServletResponseWrapper ,如此问题中所述。

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

作为参考,我在tomcat官方文档中找到了这个:

As a reference, I found this in the tomcat official documentation:


Tomcat删除';'和'charset'关键字之间的空白字符

Tomcat removes blank chars between the ';' and the 'charset' keyword

我知道http标准说分号后的空格是可选的,正如另一个所提到的那样 SO帖子但是因为有问题的客户端运行遗留版本,我想知道是否有办法强制tomcat保留这个空格。

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.

我正在考虑其他选择,例如修改apache或nginx中的内容类型头文件(在tomcat之上),但如果可能的话我更喜欢tomcat级别的解决方案。

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.

推荐答案

正如评论中所发表的那样,这是我们的意思无法避免,因为它在tomcat中被硬编码源代码

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).

谢谢@ zack6849指向那个。

Thanks @zack6849 por pointing that.

这篇关于使用tomcat在Content-type头响应中以分号保留空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆