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
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: