Monday, August 31, 2009

Why set download header to x-download?

It’s important to set the Content-Type header to a non-standard value such as application/x-download because, although the HTTP specification provides a mechanism for file downloads, many browsers second-guess the server's directives and do what they think is best rather than what they're told.

These browsers--including Microsoft Internet Explorer and Opera--look at the file extension and "sniff" the incoming content. If they see HTML or image content, they inline-display the file contents instead of offering a Save As dialog. Turns out there are no 100% reliable ways to download a file across all browsers.

According to a reference site, the HTTP specification recommends setting the Content-Type to application/octet-stream. Unfortunately, this causes problems with Opera 6 on Windows (which will display the raw bytes for any file whose extension it doesn't recognize) and on Internet Explorer 5.1 on the Mac (which will display inline content that would be downloaded if sent with an unrecognized type). So, the best way to cater for max scenario case coverage will be to set to application/x-download.

No comments: