if the server doesn't send the content-type header, how does the browser tell which kind of content he got? For example, when I get the SO logo with chrome, the image is intact, though the server doesn't state its extension (at least, explicitly)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Most browsers do content sniffing if the type is not explicitly declared in the HTTP header. They are looking for specific signatures they know and thereby guess the media type.
See the section Determining the type of a new resource in a browsing context in the HTML 5 specification or this Draft of Content-Type Processing Model for some examples.
回答2:
It can guess the content type by inspecting the file.
For example, PNG have "PNG" among the first 4 bytes.
回答3:
Different browsers handle it in different ways.
Internet Explorer guesses based on content. In fact has often ignored Content-Type
headers, instead using its own guess.
Some browsers also take the extension into account.