Class wwHTTPHeader

Customizing HTTP requests with special instructions and behaviors for browsers and other HTTP clients.

This class deals with generating an HTTP header for Web Connection requests. Although you can generate headers manually via string output this class automates the process with standard headers and common methods to add common header features such as Authentication, Redirection, HTTP Cookies and page persistance.

A basic HTTP header looks like this:

HTTP/1.0 200 OK
Content-type: text/html

Note that headers must include a blank line following the header and before the actual content (lets say an HTML document) starts.

This class is a utility class and primarily used internally by Web Connection to generate the HTTP headers for each request, but you can also access this class directly to create custom headers.

The class basically works by outputting to a wwResponse object. You can either pass in an existing wwResponse object or you can have it create one of its own internally. If you use an existing object all output is directly routed into the existing Response object and this is the mechanism that Web Connection uses internally. If you don't pass one in, wwHTTPHeader creates a wwResponseString object and you have to call the wwHTTPHeader::GetOutput method to retrieve the content.


Note:
If you use the wwHTTPHeader object and pass in an existing wwResponse object, you will most likely have to call wwHTTPHeader::CompleteHeader() to force the header to complete itself. This adds the separating blank line into the output. If you let the wwHTTPHeader create its own internal object this is not necessary - wwHTTPHeader::GetOutput() automatically adds the blank line.

*** Write out the header directly into the HTTP stream
oHeader = CREATE("wwHTTPHeader",Response)
oHeader.DefaultHeader()
oHeader.AddForceReload()
oHeader.CompleteHeader()

*** Start our HTTP content now
Response.WriteLn("<html>")
...
Response.WriteLn("</html>")


Example

*** An example creating a custom header with HTTP cookies


*** Try to retrieve the cookie...
lcId=Request.GetCookie("WWUSERID")

*** Create Standard Header
loHeader=CREATEOBJECT("wwHTTPHeader")
loHeader.DefaultHeader()

*** If not Found
IF EMPTY(lcId)
   *** Create the cookie
   lcId=SYS(3)
   
   loHeader.AddCookie("WWUSERID",lcId,"/wconnect")
   
   *** To specify a permanent cookie supply NEVER or a specific expiration date
   *** loHeader.AddCookie("WWUSERID",lcId,"/","NEVER")
ENDIF            

*** NOTE: We're passing the HTTPHeader header to HTMLHeader method

*** Send Header and make sure to pass the Content Type (loHeader)
Response.HTMLHeader("Cookie Test","Cookie Test",BACKIMG,loHeader)

Class Members

MemberDescription
AddCacheHeader Adds a Cache header to the Request that causes the page to be cached on the client.
o.AddCacheHeader(lnExpirationSeconds)
AddCookie Adds an HTTP Cookie to the HTTP request header to be returned to the client.
o.AddCookie(tcCookie, tcValue, tcPath, tcExpire)
AddCustom AddCustom works much like AddHeader() in that it generates a custom HTTP header. Some HTTP headers don't conform to the Header/Value pair syntax so this method allows you to specify a complete HTTP header line rather than the key/value pair.
o.AddCustom(lcCustomHeader)
addforcereload Adds an immediate expiration to the page so the page will always be forced to reload and not be read from cache.
o.addforcereload()
addheader HTTP allows you to specify a number of custom headers for requests that can be interpreted by clients. This is one mechanism for the server to pass down data to the client. Typically the HTTP header is used for standard headers that are supported by browsers. For example, custom types in include things like Expires, Set-Cookie, Pragma and so on. You can also add your totally custom headers in
o.addheader(lckey,lcValue)
AddRequestId Adds the Web Connection Current Request ID if available.
o.AddRequestId()
authenticate This method creates a self contained HTTP request that asks the browser to present the login dialog into which the user must type the username and password. The password is then validated by the Web server typically against the NT (or Windows) user database. The exact validation varies by Web server - IIS uses the NT User database on the server.
o.authenticate(lcRealm, lcErrorText)
ClearHeader Clears all current output in the HTTP header.
o.ClearHeader
completeheader When you pass in a Response object when the wwHTTPHeader object is created this object generates the HTTP output every time when you call one of the methods in this class. Once the header is complete it's extremely important that the trailing blank line gets generated and CompleteHeader() is meant to do this.
o.completeheader()
defaultheader This method creates a default HTTP header for standard HTML requests. The header looks like this:
o.defaultheader()
FileDownloadHeader Returns a standard File Download header. This header causes a file download dialog to be displayed instead of returning the file as content to be displayed in the browser.
o.FileDownloadHeader(lcFilename,lcContentType,lnFileSize)
getoutput Retrieves the output of the header if no Response object was passed in. The data is generated into the internal Response object and GetOutput retrieves that output as a string.
o.getoutput()
redirect Redirects the current request to another URL. HTTP redirects are an HTTP construct to allow re-routing of requests mid-stream to another URL which is useful in situations where you're for example have multiple paths of operation and you need to go back to another page or request.
o.redirect(tcUrl)
SetContenttype Content types determine the type of data that is returned from a request for the benefit of the client application. Browsers rely on content types to figure out how to display incoming data. By default browsers expect to see HTML content which is
o.setcontenttype(tcContentType)
setprotocol Sets the protocol for the HTTP header.
o.setprotocol(tcProtocol)
cHTTPVersion HTTP Version for the HTTP header.

Requirements

See also:

wwResponse::ContentTypeHeader

  Last Updated: 4/6/2008 | © West Wind Technologies, 2008