While testing the HTTP server code, I noticed something strange: if I return Content-Type: text/plain, browsers will not display the content in plain text. Instead, they seem to suggest that the server should be misconfigured, and instead they try to determine the type of content.
For example, if I return the contents of a PNG file, but with Content-Type: text/plain:
- FireFox and IE9 are watching the extension on the URL. If it ends on
.png, they display it as an image. If not (for example, if I return the same content from a URL that ends with .xyz), they suggest that I save the file. - Chrome and Opera look at the contents of the file, detect its PNG and display it as an image.
Of course, it would be pointless to return PNG in quality text/plainin production; but if I check to see if my server returns the correct one Content-Type, the behavior of browsers with two assumptions gets in the way. Plus it's just curious that I'm interested in if there is a way around it.
Is there a way - with a different Content-Typeor additional HTTP header or something else that I can tell the browser: "Show it as text, in fact, I don't know what I'm doing"?
source
share