How to support backwards compatibility with the changes to the Accept header handling in Rails 2.3.4

*爱你&永不变心* 提交于 2019-12-05 18:24:14

If I understand correctly the problem is in the Request headers. You can simply add a custom Rack middleware that corrects it.

Quick idea:

class AcceptCompatibility
  def initialize(app)
    @app = app
  end

  def call(env)
    if env['Accept'] == "application/xml" && env['Content-Type'] == "application/xml"
      # Probably an API call
      env.delete('Accept')
    end
    @app.call(env)
  end
end

And then in your environment.rb

require 'accept_compatibility'
config.middleware.use AcceptCompatibility

Embarrassingly enough, this actually turned out to be an Apache configuration issue. Once I resolved this, everything worked as expected. Sorry about that.

As coderjoe correctly pointed out, setting the Content-Type header isn't necessary at all -- only setting the Accept header.

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