Team LiB
Previous Section Next Section

Media Types

When you complete an HTTP transaction requesting content, one of the headers received by the client software tells you what type of data is being received. This header, which is provided as an Internet media type, lets the software receiving the data make a decision about how to process it. Suppose, for example, that you request a URL representing an audio file. Generally speaking, by itself the browser doesn't know how to play the arbitrary stream of bytes that it receives, but by looking at the header received, the browser can choose which player application to launch the audio file.

You are probably familiar with MIME types, the Internet standard for identifying different types of media. The HTTP standard is based on Internet Media Types, which are similar to MIME types.

When the HTTP transaction occurs, the client (generally a browser) tells the server which media types it understands using the Accept header. The server then tries to send information in one of the media types supported by the client. This information is sent using the Content-type header.

When an HTTP transaction occurs without the Accept header, the server assumes that the client supports any type of media. There are three general forms of the Accept header:

Accept: */*

Client can accept any media type.

Accept: type/*

Client can accept a class of media type. Example: image/* means that the type of images is not important.

Accept: type/subtype

Only a class and type is acceptable. Example: image/png means only png files can be accepted.

If the client accepts multiple document types, it indicates them in a single Accept: statement and uses a comma to separate them. For example:

Accept: image/jpg, image/png, image/gif


Beyond using the Content-type header with a GET method, a client might also supply a Content-type header with a POST or PUT method. This allows the format of the data being supplied in the POST or PUT operation to be specified.

    Team LiB
    Previous Section Next Section