Media Types
One of the most important functions of headers is to make it possible for the recipient of the data to know what kind of data it is receiving, and thus be able to process it appropriately. If the client didn’t know that the data returned by the server was a GIF image, it wouldn’t know how to render it on the screen. If it didn’t know that some other data was an audio snippet, it wouldn’t know to call up an external helper application. For negotiating different data types, HTTP incorporated Internet Media Types, which look a lot like MIME types but are not exactly MIME types.
The client tells the server which media types it can handle, using
the Accept
header. The server tries to return
information in one of the client’s preferred media types, and
declares the type of the data using the
Content-type
header.
The Accept
header is used to specify the
client’s preference for media formats, or to tell the server
that it can accept unusual document types. If this header is omitted,
the server assumes that the client can accept any media type. The
Accept
header can have three general forms:
Accept: */* Accept:type
/* Accept:type/subtype
Using the first form, */*
, indicates that the
client can accept an entity-body of any media type. The second form,
type/*
, communicates that an entity-body
of a certain general class is acceptable. A client may issue an
Accept: image/*
to accept images, where the type of image (GIF, JPEG, or whatever) is not important. The third form indicates ...
Get HTTP Pocket Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.