Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Internet Explorer Accept header

#3240

Internet Explorer sends a rather retarded accept header, this causes Rails to respond with a whole slew of mime types before the sensible defaults: HTML and XML. For example:

repond_to do |format|
  format.html
  format.jpg do
    send_file @photo.public_path, :type => 'image/jpeg'
  end
end

Will return the JPEG instead of the HTML version on a regular request.

Attached is a patch which prepends HTML and XML to ActionController::Request#accepts when the user agent suggests Internet Explorer.

Reported by Manfred Stienstra · September 21st, 2009 @ 01:37 PM

State: stale
Milestone: 2.3.10
Assigned to: Michael Koziarski Michael Koziarski
Importance: Medium

Activity

  1. Manfred Stienstra
  2. josh
    josh
    • State changed from new to open
    • Milestone changed from 2.x to 2.3.6
    • Assigned user changed from josh to Yehuda Katz (wycats)

    Ouch!

    +1 to apply.

    I known Yehuda made some changes to Accepts in 3.x so I'm not sure if its affected as well.

    Do you think something similar should be applied to Rack core?

    September 22nd, 2009 @ 04:28 PM

  3. Manfred Stienstra
    Manfred Stienstra

    There is nothing in Rails 3 addressing this issue as far as I can see. I don't think this belongs in Rack, it's coupled with the way Rails does content negotiation.

    September 22nd, 2009 @ 10:16 PM

  4. Yehuda Katz (wycats)
    Yehuda Katz (wycats)

    The fix in 3.0 is to reject Accept header usage if more than one MIME is specified.

    This means that:

    Accept: text/html
    

    will work, but:

    Accept: rather/retarded, ie/header
    

    will fall back to text/html.

    September 24th, 2009 @ 05:50 AM

  5. josh
    josh
    • Assigned user changed from Yehuda Katz (wycats) to josh

    September 24th, 2009 @ 05:51 AM

  6. josh
    josh
    • Assigned user changed from josh to Michael Koziarski

    Koz, can you weigh in.

    (Sorry for all the handoffs)

    September 24th, 2009 @ 05:52 AM

  7. Manfred Stienstra
  8. Michael Koziarski
    Michael Koziarski

    fwiw, this is why I added use_accept_header = false. It's a nice science experiment, but the header's basically junk in the wild.

    September 29th, 2009 @ 04:18 AM

  9. Nazgum
    Nazgum

    I tested applying this patch to rails 2.3.5 and this causes Internet Explorer to fail to respond to certain requests, for example:

    def update_chat
    @shouts = Shout.recent

    respond_to do |format|

    format.js
    

    end end

    This method, which only responds to javascript, fails with Internet Explorer once this patch is applied, as Internet Explorer responds to the first mime type, which is text/html with this patch, which does not exist in this method..

    January 5th, 2010 @ 05:05 PM

  10. Manfred Stienstra
    Manfred Stienstra
    • State changed from committed to open

    The patch was applied and reverted for specifically that reason. I guess we should reopen it and take another look.

    January 7th, 2010 @ 08:00 AM

  11. Gareth Adams
    Gareth Adams

    Could this be improved by adopting some kind of qs (quality of source) parameter to the format.* call, in the same way as Apache's content negotiation works?

    repond_to do |format|
      format.html
      format.jpg :qs => 0.8 do
        send_file @photo.public_path, :type => 'image/jpeg'
      end
    end
    

    You would have to ensure that
    - A MIME type match by extension would automatically match its exact format block - A request without an extension would be matched by a q/qs algorithm like that in Apache's content negotiation - Suitable default qs values were set for different MIME types to reflect that a) Rails prefers serving HTML documents b) Some browsers aren't very good at specifying their Accept header

    By this logic, a UA wanting to get a non-HTML response to an extensionless URI would have to either
    - Supply a q

    For example, Firefox supplies a different Accepts header for resources loaded through an tag

    Is this heading in the wrong direction? It seems to me that the Accept header is at most a guideline, so there shouldn't be any problem with using our own values to fudge the browser's requested quality values. The only problem would be doing the maths to work out the best possible 'fudge' values

    March 8th, 2010 @ 04:38 PM

  12. Rizwan Reza
  13. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.6 to 2.3.7

    May 23rd, 2010 @ 05:54 PM

  14. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.7 to 2.3.8

    May 24th, 2010 @ 09:40 AM

  15. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.8 to 2.3.9

    May 25th, 2010 @ 11:45 PM

  16. Rohit Arondekar
    Rohit Arondekar

    Any updates to this ticket? Is somebody working on a new patch?

    June 17th, 2010 @ 06:38 AM

  17. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.3.9 to 2.3.10
    • Importance changed from to Medium

    August 30th, 2010 @ 02:28 AM

  18. mikhailov
    mikhailov

    I have the same issue, but "IE Accept header related bugs" been fixed be remove this chunk of js code:
    $("form").submit(function(){

    $('input[type=submit]').attr('disabled', 'disabled');
    return true;
    

    });

    It's weird for me, because I was looking for an issue in server-side code.
    please be ensure that all is ok with your client-side scripts.

    September 4th, 2010 @ 03:40 PM

  19. sunkencity
    sunkencity

    Same problem in rails 3 with IE if having an action that can return the data in .xls format.

    October 19th, 2010 @ 02:37 PM

  20. Santiago Pastorino
    Santiago Pastorino

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:29 PM

  21. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:29 PM