开发者

What is the and why is there a difference between request.env['CONTENT_TYPE'] and request.content_type?

I'm seeing two different values for request.env['CONTENT_TYPE'] a开发者_如何学Cnd request.content_type.

From a separate application, I am sending a request to my Rails application and have explicitly set the Content-Type to text/xml.

Here is what I am seeing on the other end, from within my Rails application:

request.env['CONTENT_TYPE'] = "text/xml"
request.content_type = "application/xml"

request.content_type is actually action_dispatch.request.content_type

  1. What is the difference between request.env['CONTENT_TYPE'] and request.content_type?
  2. Why are these two values different?


request.env contains Rack's "thoughts" on what the content type is. Generally, this is the content type of the request that you have made.

request.content_type on the other hand is Rails's interpretation of what it thinks the content type is, based off the format of the request. These are defined in a file called mime_types.rb in Rails (I can't recall which part, but with that you should be able to locate it), and additional ones can be specified in config/initializers/mime_types.rb.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜