HTTP Message Flow and Message Parts - Part 1 of Chapter 3 from HTTP: The Definitive Guide (6/7) | WebReference

HTTP Message Flow and Message Parts - Part 1 of Chapter 3 from HTTP: The Definitive Guide (6/7)

To page 1To page 2To page 3To page 4To page 5current pageTo page 7
[previous] [next]

HTTP: The Definitive Guide, Chapter 3: HTTP Messages

Headers

The previous section focused on the first line of request and response messages (methods, status codes, reason phrases, and version numbers). Following the start line comes a list of zero, one, or many HTTP header fields (see Figure 3-5).

HTTP header fields add additional information to request and response messages. They are basically just lists of name/value pairs. For example, the following header line assigns the value 19 to the Content-Length header field:

Content-length: 19

Header classifications

The HTTP specification defines several header fields. Applications also are free to invent their own home-brewed headers. HTTP headers are classified into:

General headers
Can appear in both request and response messages

Request headers
Provide more information about the request

Response headers
Provide more information about the response

Entity headers
Describe body size and contents, or the resource itself

Extension headers
New headers that are not defined in the specification

Each HTTP header has a simple syntax: a name, followed by a colon (:), followed by optional whitespace, followed by the field value, followed by a CRLF. Table 3-4 lists some common header examples.

Table 3-4: Common header examples

Header example

Description

Date: Tue, 3 Oct 1997 02:16:03 GMT

The date the server generated the response

Content-length: 15040

The entity body contains 15,040 bytes of data

Content-type: image/gif

The entity body is a GIF image

Accept: image/gif, image/jpeg, text/html

The client accepts GIF and JPEG images and HTML

Header continuation lines

Long header lines can be made more readable by breaking them into multiple lines, preceding each extra line with at least one space or tab character.

For example:

HTTP/1.0 200 OK
Content-Type: image/gif
Content-Length: 8572
Server: Test Server
	Version 1.0

In this example, the response message contains a Server header whose value is broken into continuation lines. The complete value of the header is "Test Server Version 1.0".

We'll briefly describe all the HTTP headers later in this chapter. We also provide a more detailed reference summary of all the headers in Appendix C.


To page 1To page 2To page 3To page 4To page 5current pageTo page 7
[previous] [next]

Created: January 13, 2003
Revised: January 13, 2003

URL: https://webreference.com/programming/http/chap3/1/6.html