content-type of text-plain causes browser to download of file

后端 未结 2 838
野性不改
野性不改 2021-02-19 08:25

I\'m writing a web application API, where when someone accesses a URL, it returns text data. I set the content-type to \"text/plain\", but when I access it with Chrome, it down

2条回答
  •  盖世英雄少女心
    2021-02-19 09:06

    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.

提交回复
热议问题