content-type of text-plain causes browser to download of file
Laurence's explanation is correct. Only IE and Chrome is performing mime sniffing at the time of this post. You can now just set the HTTP header X-Content-Type-Options: nosniff
and it will do the trick!
It sounds like you may be running into Chrome Issue 106150. Chrome apparently (sometimes) decides to use "sniffing" logic when the content-type is text/plain.
Possible workarounds:
- Send the
X-Content-Type-Options: nosniff
header. - If the text is Unicode, include a BOM. This will tell the sniffing logic that it really is text.
- Remove "binary looking" bytes from the file. From the bug report "Any value between 0x00 and 0x1f looks binary except for ESC, CR, NP, NL, HT".
- It sounds like using an extension that's obviously supposed to be text/plain (like .txt) might disable the sniffing.