Displaying articles with tag

XML.load and Content-Encoding

Posted by Matt White, Tue Mar 06 09:22:00 UTC 2007

I was having a rather perplexing problem with Flash in IE6 the other day, and I found very little to help me until I stumbled upon this gem. We have some flash elements on a site that we built that make use of XML loaded out of a Rails app via ActiveRecord::Base.to_xml. I was using the basic Nginx config file put together by Ezra for proxying to a mongrel_cluster, which works great overall. However, as mentioned in that blog entry, IE6 doesn’t like compression or no-cache headers on XML data.

Fortunately Nginx allows you to set the header types that will have gzip compression applied, using the “gzip_types” directive in the config file. So, just make sure that your actions that generate xml have the “Content-Type: text/xml” header applied, and then remove the “text/xml” directive from the list of gzip_types in your Nginx config file.

Unfortunately you can’t use the handy-dandy Rails respond_to function, because Flash fails to correctly set the Request-Type header to text/xml. So, my only solution was to come up with xml actions to parallel with my view actions so that any request to that action would receive xml regardless of the Request-Type.

So, make sure that any actions that emit xml for Flash consumption set the following:

1
2

@headers['Content-Type'] = "text/xml"

And you should be good to go!

1 comment | Filed Under: | Tags: