从 Rails 内容类型中删除字符集 [英] Remove charset from Rails content type
问题描述
当 Content-Type 包含字符集行时,我有一个老式的愚蠢服务向我的应用程序发出请求失败
I have a old-stupid service making request to my app that fails when the Content-Type include the charset line
Content-Type text/html; charset=utf-8
而且我不知道如何从我的 rails 响应中删除它.每次我覆盖强制第一部分(内容类型文本/html)的标题时,Rails 都会将字符集添加到标题中...
and I don't know how to remove it from my rails response. Every time that I override the headers forcing just the first part (Content-Type text/html) Rails adds the charset to the header...
推荐答案
对于 Rails 3/4,处理这个的代码在 ActionDispatch::Response.assign_default_content_type_and_charset!
中的 actionpack/lib/action_dispatch/http/response.rb.
For Rails 3/4, the code that handles this is in ActionDispatch::Response.assign_default_content_type_and_charset!
in actionpack/lib/action_dispatch/http/response.rb.
设置 response.headers['Content-Type']
而不是 response.content_type
应该消除字符集.Chubas 的解决方案对所有响应执行此操作.
Setting response.headers['Content-Type']
instead of response.content_type
should eliminate the charset. Chubas' solution does this for all responses.
对于 Rails 2,处理这个的代码位于 content_type=
和 charset=
中,actionpack/lib/action_controller/response.rb.
For Rails 2, the code that handles this is in content_type=
and charset=
in actionpack/lib/action_controller/response.rb.
正如 Carson 的解决方案所描述的,设置 ActionController::Base.default_charset = nil
应该消除字符集.
As Carson's solution describes, setting ActionController::Base.default_charset = nil
should eliminate the charset.
这篇关于从 Rails 内容类型中删除字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!