Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Rails does not recognize the "text/*" MIME type #860

lighthouse-import opened this Issue May 16, 2011 · 6 comments


None yet
3 participants

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6458
Created by Roel van der Hoorn - 2011-02-21 10:36:42 UTC

Some web crawlers use the "text/*" MIME type in the HTTP ACCEPT header in their request. This makes Rails throw a MissingTemplate error.

This ticket covers only the part that "text/*" should return any text type (e.g. text/html, text/plain). And "image/*" any image type for that matter.

Note that this issue is not the same as #5113, which covers the MissingTemplate part, instead of returning a 406 (Not Acceptable), if the HTTP ACCEPT header requests only MIME types for which the respond_to block does not have an adequate response.

Imported from Lighthouse.
Comment by Anton Astashov - 2011-03-03 04:59:52 UTC

Agreed, e.g. Bing Bot uses Accept: text/*, and every its request raises ActionView::MissingTemplate exception in our app.

Imported from Lighthouse.
Comment by Diego Carrion - 2011-03-05 23:10:30 UTC

This seems to be fixed on edge.

hlxwell commented Dec 12, 2011

The recent version happened again. 3.2 beta

could you show me the fixing code?


scottwb commented Feb 6, 2012

@hlxwell - I see the fixing commits here ranging from Nov 22, 2010 to Nov 28, 2010: https://github.com/rails/rails/commits/master/actionpack/lib/action_dispatch/http/mime_type.rb, notably:

For anyone else using an earlier version of Rails that wants this fixed, but can't upgrade just yet, I have posted a monkey-patch with some test cases that you can use to work around this:


hlxwell commented Feb 7, 2012

One question is:

@synonyms of Mime::ALL is blank, still works?

ree-1.8.7-2011.03 :001 > Mime::ALL
=> #<Mime::Type:0x106424710 @synonyms=[], @symbol=:all, @string="/">
ree-1.8.7-2011.03 :002 > Mime::HTML
=> #<Mime::Type:0x1064267e0 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">

if Rails.version == "3.0.7"

I am using 3.0.11 still has this error. maybe below 3.1?


scottwb commented Feb 7, 2012

It looks like your pasted code omitted the #<Mime::Type...> stuff. Can you try pasting it in a code block or using a gist? I am curious to see what you have. Here is what mine looks like:

1.8.7 :001 > Mime::ALL
 => #<Mime::Type:0x102736970 @string="*/*", @synonyms=[], @symbol=:all> 
1.8.7 :002 > Mime::HTML
 => #<Mime::Type:0x10273ab88 @string="text/html", @synonyms=["application/xhtml+xml"], @symbol=:html>

I don't think this patch changes that behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment