How does browser know the content type when such h

2020-04-14 02:57发布

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)

3条回答
姐就是有狂的资本
2楼-- · 2020-04-14 03:19

It can guess the content type by inspecting the file.

For example, PNG have "PNG" among the first 4 bytes.

查看更多
该账号已被封号
3楼-- · 2020-04-14 03:20

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.

查看更多
叛逆
4楼-- · 2020-04-14 03:21

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.

查看更多
登录 后发表回答