respond_to, HTTP_ACCEPT, and Internet Explorer

55 views
Skip to first unread message

Jim Hoskins

unread,
Feb 7, 2008, 2:48:11 PM2/7/08
to Orlando Ruby Users Group Discussion
Yet another problem caused by my favorite browser.

So here is the situation, we are building a corporate website for our
company, mostly CMS type functionality. We want to allow stories to be
saved as word documents, among other formats.

We have gotten everything working restfully so /stories/1 is an html
represntation and /stories/1.doc is the word doc. We did this the
standard way of registering the mime type and calling format.doc in
respond_to. No problems at all in Firefox and the "real" browsers.

However, we fire up IE and attempt to load /stories/2 (no .format) and
we are served the .doc when we should receive the html page. This is
because respond_to will look at the HTTP_ACCEPT header string to
determine the desired format if none is explicitly given through
params. It is all great until you look at how IE sends these headers.

First off: The full string is only transmitted 'once per http
session', subsequent requests are sent with "*/*"
Second: Here is the string it sends out the first time:
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/
vnd.ms-excel, application/vnd.ms-powerpoint, application/msword,
application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-
xbap, application/x-ms-application, application/x-shockwave-flash,
application/x-silverlight, */* "

So if you have never read up on this header, preference is weighted
first => highest, with each preference having an optional q=# where
the # represents an explicit preference weight.

Notably on the IE string, text/html or application/xhtml+xml is
completely missing.
application/msword is defined, but not html!

So the result is IE prefers Word Documents over HTML, (which seems
like microsoft :-) )

Ideally we could change every IE users accept header, but clearly, we
can't. Rails is working as expected, but I want application/xhtml+xml
(html) to be the default if no format is explicitly defined.

Is there any way to serve a format only if params[:format] is
explicitly set, or anyway to push html onto IE's accept string to
correct the problem?

here is a string I came across in investigating this:
http://groups.google.com/group/rails-oceania/browse_thread/thread/f6d00fed2d539cb9

Jason Boxman

unread,
Feb 7, 2008, 3:57:34 PM2/7/08
to orug-di...@googlegroups.com
On Thursday 07 February 2008 14:48, Jim Hoskins wrote:
> Yet another problem caused by my favorite browser.
>
> So here is the situation, we are building a corporate website for our
> company, mostly CMS type functionality. We want to allow stories to be
> saved as word documents, among other formats.
>
<snip>

>
> Is there any way to serve a format only if params[:format] is
> explicitly set, or anyway to push html onto IE's accept string to
> correct the problem?

Here's a solution I could probably live with if it were my application.

[1] http://tinyurl.com/2bjpvj

You could certainly have Apache 2.2 rewrite the header[2] accordingly, but
trust me, you don't want to go there.

[2] http://tinyurl.com/yq5899

--

Jason Boxman
http://edseek.com/ - Open Source (tm) guides and tutorials

Jim Hoskins

unread,
Feb 7, 2008, 4:23:49 PM2/7/08
to Orlando Ruby Users Group Discussion
Solution 1 of adding if params[:format] == :pdf to our format.pdf
method seems pretty good. It still doesn't feel "right", but it won't
be that big of a hassle as there are few actions that will implement
this behavior.

Thanks
> Jason Boxmanhttp://edseek.com/- Open Source (tm) guides and tutorials
Reply all
Reply to author
Forward
0 new messages