Monday, September 04, 2006

Portion of HTTP Messages

The bulk of response messages and a few types of request messages include an element and can also include an element. In a response message, the portion is the actual data resource that is being transferred. For instance, if the request message GET //myserver.com/home.html HTTP/1.0 is received by a server, the entity portion of the response message will be the file home.html located in the Web server's root directory.

In a request message, the element is used for POSTing information to a Web server. This is used typically for submitting information entered into an HTML form by a human user or for queries being performed by some automated user-agent application.

The remainder of this section discusses the element.

Entity Header Fields
The element's fields provide additional information about the or, if the is not present (as in the case of HEAD requests), about the resource requested. These headers are optional. If sent element fields are returned, they generally follow the fields.

The following line shows the format for the element:

Entity-Header = Allow | Content-Encoding | Content-Length | Content-Type |
Expires | Last-Modified |

The element provides for the addition of new element fields without changing the entire protocol. However, if a user agent does not recognize an element field it is (and should be) ignored.

Allow

The Allow field is used to indicate which methods are supported by the resource requested in the request message. The format of the header field is
Allow = "Allow:" 1#method

An example is Allow: GET, HEAD. This header field is used to inform the user agent of which methods are valid for the resource being requested. However, it does not specify which methods are implemented by the server. Also, the use of this field does not prevent the user agent from attempting to perform other methods upon the resource. Nevertheless, it is good practice to follow the advice of this header field.

Content-Type, Content-Encoding, and Content-Length

These header fields indicate the type of resource being returned, how it is encoded, and the size of the being returned. The following lines show the respective formats for these headers:

Content-Type = "Content-Type:"
Content-Encoding = "Content-Encoding:"
Content-Length = "Content-Length:" 1*DIGIT

The Content-Type header indicates the media type used for the element. It essentially documents the format of the entity being transferred. The typical HTML document is sent with a Content-Type of text/html. If the request method is HEAD, the Content-Type represents the media type that would be returned if the request is a GET.

The Content-Type field can be used by the user agent to determine how to present the resource to the user. The content types are used by Web browsers when setting up helper applications that are external applications used to display specific file types (also known as media types). For instance, a Content-Type of audio/basic represents a sound file that the typical Web browser has to present to the user through an external application.

The Content-Encoding field is a modifier to the Content-Type header and indicates whether and how a resource has been encoded before transmission. This is used when a resource has been compressed, for example. The user agent must use the encoding information in order to decode the data received before presenting it to the human user.

The Content-Length indicates the size of the element. It is used in both request and response messages and is, in fact, required in request messages. The size is the number of octets sent to the recipient. If the message is a response to a HEAD request, the Content-Length field indicates the size that would have been returned by a response to a GET request on the same resource.

Expires

As the name of this header field indicates, the Expires entity header indicates the date after which the entity should be considered expired or invalid. This can be returned by applications that are generating real-time data, for example, to indicate the date (and time) after which the entity should be considered as old news. Caches should not retain the entity after the date specified.
The presence of an Expires header does not mean that the resource will change or no longer exist after the value specified, but simply that it will be "stale" (to use the wording from the Internet-Draft). If the value specified is 0 or is an invalid HTTP date, the resource should be considered as immediately expired and should not be cached in any way.

The format for the Expires header is

Expires = "Expires:"
Last-Modified

The Last-Modified header field indicates the date that the server believes the resource was last changed. The value is interpreted differently depending on the nature of the resource being transferred. This header can be used to determine whether a new copy of a resource should be retrieved or if the user should be notified that the resource has been changed. For a file resource, it is most likely to be the date that the file was last saved. For a database resource, this field can be used to indicate the date a record was last updated. The possibilities are endless.

The format for the Last-Modified header is
Last-Modified = "Last-Modified:"

When you write server-side applications, it is important to think about how this field should be used if the resource is time-sensitive. If you're writing a user-agent application, take care when attempting to interpret this field's value.