views:

59

answers:

3

Hello, 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)

+2  A: 

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.

Gumbo
+2  A: 

It can guess the content type by inspecting the file.

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

Greg
+1  A: 

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.

Stef