Proper mime negotiation in case of non-ajax request#7464
Proper mime negotiation in case of non-ajax request#7464LTe wants to merge 2 commits intorails:masterfrom LTe:mime_negotiation
Conversation
Rails should recognize accept type and respond with proper format. Request type should not matter. If a client asks for JSON, we deliver him json.
Accept header is still valid when HTTP request is not XHR type
|
Browsers were used to send completely non-sense accept headers. For example, IE were used to ask for a png file with higher priority than text/html. We could eventually merge this pull request, but we would need to check first if browsers are sending proper accept headers, otherwise this change could make an application completely unusable. |
|
Let's just say that we find out that IE6 is doing something stupid. Maybe we do not care as this browser is not supported in our project and we would like to drop workarounds in favor of following the http spec. What do you think about adding config for browser compatibility into rails ex.: config.browsers.ie = 8This could mean that we want to support Could that be helpful ? |
|
It may be relevant to this discussion:
|
|
I'm fine with dropping support for IE6, as long as this behavior is extracted to a plugin - I don't like the idea of adding another setting and keeping such legacy things in core. This should be rather trivial to implement and we could point people to it in the CHANGELOG. |
|
👍 for the @drogus proposal |
|
For the purpose of this discussion, this change will screw safari and chrome since they give higher priority to xml, according to this link: https://developer.mozilla.org/en-US/docs/HTTP/Content_negotiation So I really can't see how we can trust browsers accept headers. |
|
Fun: We should probably convince browsers to send a X-Im-a-Browser: true header. |
:'( 😢 More about the situation than about your statement. |
|
@josevalim According to https://bugs.webkit.org/show_bug.cgi?id=27267 Safari and Chrome should be OK.
|

Currently when client send request to rails with proper
Acceptheader rails will return always HTML. When I needJSONor other format I can of course add.(:format)and rails will recognize this. Why is this the only option?HTTP_X_REQUESTED_WITHis not setapplication/json, text/javascript, */*; q=0.0:jsonin controller definitionrespond_within action and give it an object that hasto_jsonandas_jsonmethod implementedWhen I ask for
JSONrails should respond withJSON.