使用 tomcat 在 Content-type header 响应中保留分号后的 space
Keep the space after semicolon in Content-type header response using tomcat
我们有一个 legacy 客户端使用部署在 tomcat 8.5 上的 servlet。
此旧客户端正在等待此格式的 content-type header 响应(注意分号和 'charset' 之间的空格):
Content-type: text/xml; charset=utf-8
然而,在服务器端,Tomcat 总是修剪这个空白,尽管我们在 servlet 中强制这样做:
response.setContentType("text/xml; charset=utf-8");
甚至在自定义扩展名为 HttpServletResponseWrapper
的过滤器中,如 this question 中所建议。
无论我尝试什么,返回的 content-type header 总是没有空格。
Content-type: text/xml;charset=utf-8
作为参考,我在tomcat官方documentation:
中找到了这个
Tomcat removes blank chars between the ';' and the 'charset' keyword
我知道 http 标准说分号后的空格是可选的,正如另一个 SO post 中提到的,但是由于有问题的客户端运行的是旧版本,我想知道是否有任何强制 tomcat 保留此空格的方法。
我正在考虑其他选择,例如修改 apache 或 nginx 中的 content-type header(tomcat 以上),但如果可能的话,我更喜欢tomcat级.
如有任何帮助,我们将不胜感激。
如评论中所述,这是我们无法避免的,因为它已硬编码在 tomcat source code
在我们的特定用例中,我们终于能够稍微更改 legacy-client,因此现在它可以处理标准格式的内容类型 header(没有 space).
感谢@zack6849 指点。
我们有一个 legacy 客户端使用部署在 tomcat 8.5 上的 servlet。 此旧客户端正在等待此格式的 content-type header 响应(注意分号和 'charset' 之间的空格):
Content-type: text/xml; charset=utf-8
然而,在服务器端,Tomcat 总是修剪这个空白,尽管我们在 servlet 中强制这样做:
response.setContentType("text/xml; charset=utf-8");
甚至在自定义扩展名为 HttpServletResponseWrapper
的过滤器中,如 this question 中所建议。
无论我尝试什么,返回的 content-type header 总是没有空格。
Content-type: text/xml;charset=utf-8
作为参考,我在tomcat官方documentation:
中找到了这个Tomcat removes blank chars between the ';' and the 'charset' keyword
我知道 http 标准说分号后的空格是可选的,正如另一个 SO post 中提到的,但是由于有问题的客户端运行的是旧版本,我想知道是否有任何强制 tomcat 保留此空格的方法。
我正在考虑其他选择,例如修改 apache 或 nginx 中的 content-type header(tomcat 以上),但如果可能的话,我更喜欢tomcat级.
如有任何帮助,我们将不胜感激。
如评论中所述,这是我们无法避免的,因为它已硬编码在 tomcat source code
在我们的特定用例中,我们终于能够稍微更改 legacy-client,因此现在它可以处理标准格式的内容类型 header(没有 space).
感谢@zack6849 指点。