After downloading Windows XP Service Pack 2 recently, I was shocked that IE was now sending HTML documents with a
.html extension as
text/plain, thus causing any the W3C Markup Validator to issue this warning message:
Sorry, I am unable to validate this document because its content type is
text/plain, which is not currently supported by this service.
The Content-Type field is sent by your web server (or web browser if you use the file upload interface) and depends on its configuration. Commonly, web servers will have a mapping of filename extensions (such as “.html”) to MIME
Content-Typevalues (such as
That you recieved this message can mean that your server is not configured correctly, that your file does not have the correct filename extension, or that you are attempting to validate a file type that we do not support yet. In the latter case you should let us know that you need us to support that content type (please include all relevant details, including the URL to the standards document defining the content type) using the instructions on the Feedback Page.
This essentially means that it was impossible to validate any local HTML document using IE. This is really annoying, especially for any unfortunate developers who are forced to develop using only IE at work. Although I do pity anyone in that situation, there is now some relief!
After spending about half an hour searching through the registry for any setting that could be causing
.html files to be sent as
text/plain, I realised that it would be eaiser to find where the setting for other content types that do work, such as CSS. So, I found the setting for that, modified, and tested. When the CSS
Content Type value was set to anything but
text/html, IE uploaded the file with that MIME type. Thus, I came to the conclusion that it was not that the setting was incorrect, but that something in Windows security was preventing any
text/html content being sent by changing it to
text/plain on the way.
After that, I tried setting the valud for
.html files to another type that the validator may support, such as
application/sgml, but sadly, without luck! But, just before giving up all hope, I realised that perhaps Windows security, being as insecure as ever, is only checking for an exact match on the content type being set by IE with file uploads. I was correct!
In a normal HTTP header, the
Content-Type can also include a
charset parameter. For example:
Content-Type: text/html; charset=UTF-8
So, I figured, what if I want IE to send a charset parameter also. I set the
Content Type value in the registry to that above, and it worked perfectly — the file validated!!! However, the charset will not always be
UTF-8, or any other charset for that matter, so I removed the chaset parameter, and was left with the value
text/html; That extra little semi-colon on the end is enough to bypass Windows security, and validate any HTML file.
Then, I remembered that IE also does not know how to validate XHTML documents either. So, I went to the registry key for
.xhtml files, added the
application/xhtml+xml MIME type, tested and Guess What! It Worked.
I have exported the required settings from the registry and they are availble here. IE6-SP2-Content-Type-text-html.reg will fix the value for
text/html, and IE6-SP2-Content-Type-application-xhtml+xml.reg will add the MIME type for XHTML documents. Download them both, inspect their contents to ensure that they are safe, and apply them by launching them. You will be prompted by Windows to confirm that you want to apply the settings.