• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why Content-Type?

 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether Content-Type is mandatory to set? what it is for? if the <HTML> is sent to client, isn't the type is deducable?
Where is content-type when I locally load page?.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by G Vanin:
Whether Content-Type is mandatory to set? what it is for? if the <HTML> is sent to client, isn't the type is deducable?

It is, and indeed this is roughly how Unix systems recognise file types: by examining the first bytes of the file (the "magic"). Windows works differently; Windows looks at the file extension (.html or .htm) and associates extensions with content types and applications.
Both methods are ugly kludges. The content type is meta-information; it is not part of the data itself, it is information about the data. Therefore it should not be required to be part of the data (as in Unix), nor do you want bizarre rules for filenames (as in Windows). The cleanest implementation for providing metadata is actually the Macintosh resource fork. But that is a Mac-specific construction.
For the web, a better, cross-platform solution was needed. So messages (whether they are mail messages, news messages, HTTP requests or HTTP responses) are split into a header with meta-information in a "Field: Value" format, and a body with the actual data. One of those header fields is the Content-Type.
Where is content-type when I locally load page?
If you're using Windows, then the operating system derives the content type from the ".html" file extension. Browsers usually carry their own extension-to-content-type mapping for when you open local files or to get out of the mess if the server does not provide a sensible content type.
- Peter
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Peter,
That was rather verry blurred to me

Because, while it is true for MS IE. It is generally masqueraded in MS applications since when you SaveAs you have a choiche of both type and name.
It is possible to rename *.txt file to .doc file and it will be insisting on its txt-type loosing formatting, drawings, etc, notwithstanding
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic