This project is archived and is in readonly mode.

#3541 ✓committed
Paul Sadauskas (Rando)

Content Negotiation Regression

Reported by Paul Sadauskas (Rando) | December 5th, 2009 @ 12:18 AM | in 3.0.2

A recent change in Rails3 rendering/respond_to code completely broke content negotiation. This commit[1] causes any request that 1) does not have a .format param, 2) is not xhr, and 3) CONTAINS A COMMA in the Accept header to return an html document.

So if, for example, you have a resource that provides html, xml, and json, and a web service client that accepts both xml and json, you get html. Also, if you have a web service similar to Sun's Cloud offering which uses custom mime-types to indicate various flavors of json, you would get html. If the resource does not provide an html content-type at all, you would get a 406 Not Acceptable response!

I discussed this with Yehuda, and this change was intended, to work around a bug in Safari's Accept header, which prefers xml over html. The way this was avoiding in Rails 2.x was to make sure the html block occured first in the respond_to block. I'm not sure if the recent changes to support respond_with prompted this change, but I hope that it be reverted to the old behaviour.

The easiest solution is to just ignore the quality parameter of the accept header, and just serve the first acceptable response. This would still require users to specify the html first, but it should not be a problem if it is well-documented. Another solution, that is more magical, would be to always prefer html over everything else, if the client accepts html or /.

I have attached[2] a failing test to demonstrate this behavior.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>


Referenced by