[cs631apue] Content Type header Media Types

Jan Schaumann jschauma at stevens.edu
Sat Nov 17 22:06:08 EST 2012


jphillip <jphillip at stevens.edu> wrote:
> My understanding after reading the RFC is that the Entity-Body is the  
> name given to the data part of the response message that is the returned  
> resource.  The RFC says we should include a Content-Type when we return  
> an Entity-Body.  So we should always be including an entity header and a  
> Content-Type field when we successfully find and return the requested  
> resource.  Is that basically correct?

That is correct.  However, in this assignment you are allowed to take a
significant shortcut:

> What should be our approach for determining the media type that is  
> returned in the Content-Type header field?

Disregarding extra credit components at this time, it is acceptable for
you to return a Content-Type of 'text/html' regardless of whatever data
you actually return.

> Should our server presume to know something about the files based on
> the file extensions or other file attributes?

Certainly not based on file names -- as we know very well, the
characters in which a filename happens to end are irrelevant to the Unix
system.

Most unix webservers identify a file's type by looking at the first
couple of bytes and guessing (based on known conventions) what this
indicates.  This is the same approach as taken by the file(1) command.
Take a look at the manual page and the file /usr/share/file/magic, or
try it out on a few different file types.

Now if you wanted to, you could try to use this data (or even shell out
to the file(1) command) to identify the correct Content-Type, but as I
mentioned above, you are not required to do so.

-Jan


More information about the cs631apue mailing list