Understanding HTTP Headers in Web Connection


HTTP uses headers to to communicate request information from the client to the server and the server to the client. Typically headers are hidden from you as the server and browser parses them behind the scenes. To get an idea of what an HTTP header looks like try the following from the command window:
DO WCONNECT
oip = CREATE('wwIPStuff')
oIP.HTTPConnect('www.microsoft.com')
lcData = '
oIP.HTTPGetEx('/',@lcData)
CLEAR
? oIP.cHTTPHeaders
What you should see is something like this: HTTP/1.1 200 OK Server: Microsoft-IIS/5.0 Content-Location: http://www.microsoft.com/Default.htm Date: Mon, 24 Apr 2000 20:47:26 GMT Content-Type: text/html Accept-Ranges: bytes Last-Modified: Mon, 24 Apr 2000 18:01:16 GMT ETag: '1057b71517aebf1:61bb' Content-Length: 15824 <html> document content goes here... </html> An HTTP header is always made up of individual lines separated by CHR(13) + CHR(10) each and an empty line that separates the HTTP header from the document's content. The content of the document is described in the Content-Type header - in the example above text/html. The content type is extremely important as it tells the client what kind of content to expect. A browser for example looks at the content type to see at how to display the data. So you can send text/xml and be able to view XML or application/pdf to see an Adobe Acrobat document in its viewer. Every server generated request should output an HTTP header although at minimum it only needs to include a status code and content type: HTTP/1.1 200 OK Content-Type: text/html Content Length can also be useful if you're sending binary data to a client. Clients can use the content length value to figure out how much data they're downloading and potentially provide status information. For Web pages binary downloads require a content length to show you a progress dialog (downloading x of y bytes).

How Web Connection handles HTTP headers

In Web Connection headers can be generated in a number of different ways.

When you see an HTTP header in your HTML output

If you see an HTTP header in the HTML output of your page it means that you generated two headers instead of one. Most likely you used the wwHTTPHeader object to physically create your own HTTP header and output it into the HTML page. You then most likely called another method such as ExpandScript to output yet another header. The way to fix this is to use the wwHTTPHeader object and pass it to the header generating method:
loHeader = CREATE('wwHTTPHeader')
loHeader.DefaultHeader()
loHeader.AddCookie('testcookie','rick')

Response.ExpandTemplate('somepage.wc',loHeader)
This causes ExpandScript to use the header you passed instead of the default header it would generate without the parameter.


Last Updated: 04/24/00