HTTP Headers

An HTTP message consists of the following:

  • HTTP header
  • body
  • trailer

The HTTP header consists of:

  • A request or response line
    • An HTTP request line contains a method, URL, and version
    • A response line contains a version, status code, and reason phrase
  • A MIME header

A MIME header is comprised of zero or more MIME fields. A MIME field is composed of a field name, a colon, and (zero or more) field values. The values in a field are separated by commas. An HTTP header containing a request line is usually referred to as a request. The following example shows a typical request header:

  1. GET http://www.tiggerwigger.com/ HTTP/1.0
  2. Proxy-Connection: Keep-Alive
  3. User-Agent: Mozilla/5.0 [en] (X11; I; Linux 2.2.3 i686)
  4. Host: www.tiggerwigger.com
  5. Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
  6. Accept-Encoding: gzip
  7. Accept-Language: en
  8. Accept-Charset: iso-8859-1, *, utf-8

The response header for the above request might look like the following:

  1. HTTP/1.0 200 OK
  2. Date: Fri, 13 Nov 2009 06:57:43 GMT
  3. Content-Location: http://locutus.tiggerwigger.com/index.html
  4. Etag: "07db14afa76be1:1074"
  5. Last-Modified: Thu, 05 Nov 2009 20:01:38 GMT
  6. Content-Length: 7931
  7. Content-Type: text/html
  8. Server: Microsoft-IIS/4.0
  9. Age: 922
  10. Proxy-Connection: close

The following figure illustrates an HTTP message with an expanded HTTP header.

Figure 10.1. HTTP Request/Response and Header Structure

HTTP Request/Response and Header Structure

HTTP Request/Response and Header Structure

The figure below shows example HTTP request and response headers.

Figure 10.2. Examples of HTTP Request and Response Headers

Examples of HTTP Request and Response Headers

Examples of HTTP Request and Response Headers

The marshal buffer or TSMBuffer is a heap data structure that stores parsed URLs, MIME headers, and HTTP headers. You can allocate new objects out of marshal buffers and change the values within the marshal buffer. Whenever you manipulate an object, you must require the handle to the object (TSMLoc) and the marshal buffer containing the object (TSMBuffer).

Figure 10.3. Marshal Buffers and Header Locations

Marshal Buffers and Header Locations

Marshal Buffers and Header Locations

The figure above shows the following:

  • The marshal buffer containing the HTTP request, reqest_bufp
  • TSMLoc location pointer for the HTTP header (http_hdr_loc)
  • TSMLoc location pointer for the request URL (url_loc)
  • TSMLoc location pointers for the MIME header (mime_hdr_loc)
  • TSMLoc location pointers for MIME fields (fieldi_loc)
  • TSMLoc location pointer for the next duplicate MIME field (next_dup_loc)

The diagram also shows that an HTTP header contains pointers to the URL location and the MIME header location. You can obtain the URL location from an HTTP header using the function TSHttpHdrUrlGet. To work with MIME headers, you can pass either a MIME header location or an HTTP header location to MIME header functions . If you pass an HTTP header to a MIME header function, then the system locates the associated MIME header and executes the MIME header function on the MIME header location.