Contypesux

by Alexander Thomas (aka Dr. Lex)
Mail

What is it?

In short, it's a script that, in combination with a .htaccess redirect, plays nice with a not-so-nice non-standard construct that only Internet Explorer uses. (As far as I know this no longer exists in modern browsers, so the purpose of this webpage is now mostly historical.)

Few people seem to be aware of the existence of something called “contype” that is part of many versions of Internet Explorer. The story behind this contraption could be found in the former MS knowledge base (which now probably links to a generic support page), but I'll give a short summary here. Someone at Microsoft realised that in some cases, a media file can be downloaded multiple times before a plug-in can render it. The multiple downloads are due to the fact that the plug-in first needs to know what “content type” the media file is. Back in the days when animals could still speak, people invented the HEAD HTTP request for that. So you'd think, well, they just do a HEAD request first and then a regular GET request. Nice try, but no cigar.

The quintessential Microsoft solution to solving problems for which a fully standards-compliant solution already exists, is to create something completely proprietary that breaks existing systems. In this case they made IE first do an ordinary GET request with “contype” as user-agent identifier. The web server is then supposed to only return a set of HTTP headers with the correct “content-type” field. In reality, no web server except maybe IIS knows about the contype contraption, and will obey to the GET request as described in RFC 2616, and return the entire huge media file. All that data will be ignored, and IE will do the real GET afterwards, effectively doubling your used bandwidth for nothing (ironically, this is exactly what it was supposed to avoid). Worse, if downloading the file takes longer than 10 seconds, contype will timeout and the plugin will fail. This atrocity is still in IE7 and I wonder if anybody at Microsoft even knows about its existence anymore. It's probably just another part drowned in the massive heap of bloated cruft that is Microsoft source code.

The most correct thing to do would be to return ‘403 Forbidden’ to any request made by the ‘contype’ user-agent. However, as a massive amount of the human population is more or less forced to use Internet Explorer, it would be unfair to punish all those people. So my solution is to emulate the correct behaviour with a combination of a .htaccess directive and a CGI script. The script does return an insult to the offending browser in the form of a warning header, but I'm afraid IE doesn't care.

Download and Usage

Download the contypesux.pl script (gzip compressed Perl script)

This script should be put in your cgi-bin directory or any other place where CGI scripts can be executed. Don't forget to make it executable. Next, put the three lines below into a ‘.htaccess’ file inside each directory that contains large binary files like PDF, MOV, MP3, ... To make it easier on yourself, you can cluster all those files together in a small set of directories.

  RewriteEngine on
  RewriteCond %{HTTP_USER_AGENT} ^contype
  RewriteRule ^.* /cgi-bin/contypesux.pl [L]

The way it works is pretty simple: the htaccess directive will reroute each request from ‘contype’ to the CGI script (if your CGI directory is not /cgi-bin/, don't forget to modify the third line of the htaccess file). This script will return a HTTP header with the correct MIME type, guessed from the requested file's extension. The script already contains the most common extensions, but feel free to add your own.

There are no warranties, express or implied, including the implied warranty of merchantability and fitness for a particular purpose. In other words, use at your own risk (but if you look inside the script you'll see that it would be a feat if it caused harm).
This script is released under the GNU General Public License.