ColdFusion in Context: Examine HTTP Headers
HTTP, Hypertext Transfer Protocol, provides the thread with which the fabric of the Web is sewn. Suppose you want to examine its message headers. Here's how.
Make a Sender
Create a sending page containing trivial content and some headers. Specifically, set a cookie that expires in two days, and set a cache-control header of "must-revalidate". Put the code in send.cfm. (Postpone the explanation of must-revalidate for now.)
<cfcookie name="mycookie" value="mytext" expires="2">
<cfheader name="cache-control" value="must-revalidate">
Hello, World.
Make a Receiver
Create a receiving page that captures the http content of the sender. Call it receive.cfm. Replace the URL below with the full URL of sender.cfm. To get information, use method=get. cfdump saves the trouble of parsing and displaying the structure of the HTTP information (contained in ColdFusion structure cfhttp).
<cfhttp url="http://127.0.0.1/context/headers/send.cfm"
method="get">
</cfhttp>
<cfdump var="#cfhttp#">
Browse Receiver
When you browse receiver.cfm, you'll see content similar to the following (but arranged in nested tables with different layout):
FILECONTENT
Hello, World.
HEADER
HTTP/1.0 200 OK
Date: Monday, 06-Jan-03 05:48:38 GMT
Server: {your server software, such as IIS}
Allow-ranges: bytes
Content-type: text/html
cache-control: must-revalidate
Page-Completion-Status: Normal
Set-Cookie:
MYCOOKIE=mytext;
expires=Tue, 07-Jan-2003 23:48:38 GMT;
path=/;
MIMETYPE
text/html
RESPONSEHEADER
ALLOW-RANGES: bytes
CACHE-CONTROL: must-revalidate
CONTENT-TYPE: text/html
DATE: Monday, 06-Jan-03 05:48:38 GMT
EXPLANATION: OK
HTTP_VERSION: HTTP/1.0
PAGE-COMPLETION-STATUS: Normal
SERVER: {your server software, such as IIS}
SET-COOKIE
MYCOOKIE=mytext;
expires=Tue, 07-Jan-2003 23:48:38 GMT;
path=/;
STATUS_CODE: 200
STATUSCODE
200 Success
That's a mouthful. Let's chew it slowly. The file content is of course, "Hello, World". The MIME type is text/html, typical for Web pages. STATUSCODE (Status Code) has a standard number (200) and a human-readable interpretation (Success).
ColdFusion has pre-digested the header information for you in a structure called "RESPONSEHEADER". This structure displays each header (or piece of the overall header, if you prefer to think of it that way) separately.
- If it was permissible to reload just a portion of the page, the measurement used would be in bytes.
- If other indicators lead the browser or cache to believe that the data might be outdated, it must revalidate its copy.
- The content type is text/html.
- The GMT date/time it was supplied is shown.
- The GMT date/time after which the object is expected to be outdated is shown.
- The explanation of the message is "OK".
- The HTTP version is 1.0 (legacy).
- The page completion status is normal.
- The server software identification is shown.
- Cookie details are provided. Notice that ColdFusion supplied the path for which the cookie is valid. (In this case, it's at the root: valid for the entire domain.)
- The numeric status code is 200.
Interesting Results
You can send headers that a legacy Web server doesn't understand, headers that might nevertheless be interpreted correctly by the modern caches and browsers that receive them. cache-control headers are part of HTTP/1.1 protocol, yet ColdFusion was able to send a cache-control header using a legacy Web server that only understands HTTP/1.0.
See what your Web host provides by default. Add headers as you see fit. Point your browser to other sites, and learn from the results. =Marty=
[For my ISP, I pointed this to http://www.futureec.com/context/headers/send.cfm instead of to 127.0.0.1....]