HTTPMESSAGE Class Reference

Class to encapuselate an HTTP message. More...

#include <mi32/httpmsg.h>

List of all members.

Public Types

enum  METHOD {
  METHOD_REPLY = 0, METHOD_OPTIONS = 1, METHOD_GET, METHOD_HEAD,
  METHOD_POST, METHOD_PUT, METHOD_DELETE, METHOD_TRACE,
  METHOD_CONNECT, METHOD_NUM_METHODS = 16
}
enum  STATUS {
  STATUS_EmptyMessage = 0, STATUS_Continue = 100, STATUS_OK = 200, STATUS_Created = 201,
  STATUS_Accepted = 202, STATUS_NonAuthoritativeInfo = 203, STATUS_NoContent = 204, STATUS_ResetContent = 205,
  STATUS_PartialContent = 206, STATUS_MultipleChoices = 300, STATUS_MovedPermanently = 301, STATUS_Found = 302,
  STATUS_SeeOther = 303, STATUS_NotModified = 304, STATUS_UseProxy = 305, STATUS_TemporaryRedirect = 307,
  STATUS_BadRequest = 400, STATUS_Unauthorized = 401, STATUS_PaymentRequired = 402, STATUS_Forbidden = 403,
  STATUS_NotFound = 404, STATUS_MethodNotAllowed = 405, STATUS_NotAcceptable = 406, STATUS_ProxyAuthenticationRequired = 407,
  STATUS_RequestTimeOut = 408, STATUS_Conflict = 409, STATUS_Gone = 410, STATUS_LengthRequired = 411,
  STATUS_PreconditionFailed = 412, STATUS_RequestEntityTooLarge = 413, STATUS_RequestURITooLarge = 414, STATUS_UnsupportedMediaType = 415,
  STATUS_RequestedRangeNotSatisfiable = 416, STATUS_ExpectationFailed = 417, STATUS_InternalServerError = 500, STATUS_NotImplemented = 501,
  STATUS_BadGateway = 502, STATUS_ServiceUnavailable = 503, STATUS_GatewayTimeOut = 504, STATUS_HTTPVersionNotSupported = 505
}

Public Member Functions

 HTTPMESSAGE (const HTTPMESSAGE &rhs)
 HTTPMESSAGE ()
 ~HTTPMESSAGE ()
void AddHeader (const STRUTF8 &header)
ERRVALUE AppendToBody (const MISTRING &data)
ERRVALUE AppendToBody (const void *data, int numbytes)
void ClearDestFile ()
void CloseDestFile ()
UINT8DetachData ()
void GenerateEscapedRequestURI (STRUTF8 &uri) const
ERRVALUE GetContent (XMLDOC &mistr) const
ERRVALUE GetContent (STRUTF8 &mistr) const
ERRVALUE GetContent (MISTRING &mistr) const
bool GetContentCharEncoding (STRUTF8 &str) const
CHAR_ENCODING GetContentCharEncoding () const
const char * GetContentType () const
const UINT8GetData () const
const FILEPATHGetDestFile () const
const STRUTF8GetEscapedRequestURI () const
const MILIST< STRUTF8 > & GetExtraHeaders () const
const char * GetHeaderString (const char *key) const
bool GetKeepAlive () const
const DATETIMEGetMessageTime () const
const STRUTF8GetMultiPartBoundary () const
int GetNumBytes () const
int GetNumBytesExpected () const
METHOD GetRequestMethod () const
const STRUTF8GetRequestURI () const
STATUS GetStatusCode () const
const STRUTF8GetStatusMessage () const
const DATETIMEGetTimeLastModified () const
bool HasCharEncoding () const
bool IsCachedResult () const
bool IsDirectToFile () const
bool IsHeadRequest () const
HTTPMESSAGEoperator= (const HTTPMESSAGE &rhs)
ERRVALUE Reserve (int size)
void Reset ()
ERRVALUE Resize (int size)
void SetContentCharEncoding (const char *encoding)
void SetContentCharEncoding (CHAR_ENCODING encoding)
void SetContentType (const char *ContentType)
void SetDestFile (const FILEPATH &filepath)
void SetIsCachedResult (bool bCachedResult)
void SetKeepAlive (bool bKeepAlive=true)
void SetMessageTime (const DATETIME &dts)
void SetRequest (METHOD method, const STRUTF8 &uri, bool bIsEscaped=false)
void SetStatusCode (STATUS status)
void SetStatusMessage (const char *msg)
void SetTimeLastModified (const DATETIME &dts)

Static Public Member Functions

static MISTRING GetStatusText (STATUS status)

Detailed Description

Class to encapuselate an HTTP message.

When recieving a message, this class holds both the headers and the message body in its raw form, which you can retrieve as raw data, MISTRING, STRUTF8, or an XMLDOC.

When sending a message, you can store the body in the HTTPMESSAGE or you can use HTTPMESSAGE to hold just the headers and use one of the many versions of HTTPCLIENT::SendMessage() which take the body as a seperate parameter.


Member Enumeration Documentation

Enumerator:
METHOD_REPLY 
METHOD_OPTIONS 
METHOD_GET 
METHOD_HEAD 
METHOD_POST 
METHOD_PUT 
METHOD_DELETE 
METHOD_TRACE 
METHOD_CONNECT 
METHOD_NUM_METHODS 

HTTP status codes as defined by RFC-2616 1xx Informational 2xx Successful 3xx Redirection 4xx Client error 5xx Server error.

Enumerator:
STATUS_EmptyMessage 
STATUS_Continue 
STATUS_OK 
STATUS_Created 
STATUS_Accepted 
STATUS_NonAuthoritativeInfo 
STATUS_NoContent 
STATUS_ResetContent 
STATUS_PartialContent 
STATUS_MultipleChoices 
STATUS_MovedPermanently 
STATUS_Found 
STATUS_SeeOther 
STATUS_NotModified 
STATUS_UseProxy 
STATUS_TemporaryRedirect 
STATUS_BadRequest 
STATUS_Unauthorized 

Password required.

STATUS_PaymentRequired 
STATUS_Forbidden 

No permission.

STATUS_NotFound 
STATUS_MethodNotAllowed 
STATUS_NotAcceptable 
STATUS_ProxyAuthenticationRequired 
STATUS_RequestTimeOut 
STATUS_Conflict 
STATUS_Gone 
STATUS_LengthRequired 
STATUS_PreconditionFailed 
STATUS_RequestEntityTooLarge 
STATUS_RequestURITooLarge 
STATUS_UnsupportedMediaType 
STATUS_RequestedRangeNotSatisfiable 
STATUS_ExpectationFailed 
STATUS_InternalServerError 
STATUS_NotImplemented 
STATUS_BadGateway 
STATUS_ServiceUnavailable 
STATUS_GatewayTimeOut 
STATUS_HTTPVersionNotSupported 

Constructor & Destructor Documentation

HTTPMESSAGE::HTTPMESSAGE (  ) 

Default constructor.

HTTPMESSAGE::HTTPMESSAGE ( const HTTPMESSAGE rhs  ) 

Copy constructor.

HTTPMESSAGE::~HTTPMESSAGE (  ) 

Member Function Documentation

void HTTPMESSAGE::AddHeader ( const STRUTF8 header  ) 

Add an additional header not covered by the other Set methods.

If you try to add a header that already exists in the message, it will replace the existing header

ERRVALUE HTTPMESSAGE::AppendToBody ( const MISTRING data  ) 

Append MISTRING to body of message.

ERRVALUE HTTPMESSAGE::AppendToBody ( const void *  data,
int  numbytes 
)

Append data to body of message.

This method is used to allow setting the body of a message to be sent generally by post.

void HTTPMESSAGE::ClearDestFile (  ) 

Clear the destination file.

If the HTTPMESSAGE was last used to recieve directly to a file, this method resets it so that the HTTPMESSAGE can be reused without overriting the same file. See SetDestFile() for details

void HTTPMESSAGE::CloseDestFile (  ) 

Close the destination file.

See SetDestFile() for details

UINT8* HTTPMESSAGE::DetachData (  ) 

Detach and return a pointer to the raw message body data.

This method calls Detach on the body data buffer and returns the pointer. You should call GetNumBytes() before calling this method. This method obviously won't work if you've redirected the body to a file by calling SetDestFile(). The caller is responsible for freeing the buffer.

void HTTPMESSAGE::GenerateEscapedRequestURI ( STRUTF8 uri  )  const

Get the escaped URI for the request.

This is like GetRequestURI, but escapes the URI by the rules of RFC1738.

ERRVALUE HTTPMESSAGE::GetContent ( XMLDOC mistr  )  const

Get the message body as an XML document This method works with the following ContentTypes text/xml text/html text/plain - will create a single text node multipart/form-data - This is how HTML forms submit via POST The document will have a "control" node for each value.

Each node will have a "name" attribute which holds the name of the control from the form. application/x-www-form-urlencoded - This is how HTML forms submit via GET. XML document format is the same as for multipart/form-data

ERRVALUE HTTPMESSAGE::GetContent ( STRUTF8 mistr  )  const

Get the message body as a STRUTF8.

ERRVALUE HTTPMESSAGE::GetContent ( MISTRING mistr  )  const

Get the message body as an MISTRING.

bool HTTPMESSAGE::GetContentCharEncoding ( STRUTF8 str  )  const

Get the content character encoding.

The encoding string is defined by some RFC that I have to look up.

Returns:
true if the encoding was set, false if not
CHAR_ENCODING HTTPMESSAGE::GetContentCharEncoding (  )  const

Get the content character encoding.

Note, if no encoding is specified or is meaningless (such as for binary data), the encoding will be assumed to be UTF8

const char* HTTPMESSAGE::GetContentType (  )  const

Get the value of the Content-Type in the HTTP header.

This will only be the MIME type. If the Content-Type specified a charencoding, it will have been parsed and you should use GetContentCharEncoding() to retrieve it.

const UINT8* HTTPMESSAGE::GetData (  )  const

Get a pointer to the body data (const) Note: there is also a DetachData() method which will detach the buffer from the HTTPMESSAGE, eliminating the need to copy it.

This method obviously won't work if you've redirected the body to a file by calling SetDestFile().

const FILEPATH& HTTPMESSAGE::GetDestFile (  )  const

Get the destination file.

If the HTTPMESSAGE is set to retrieve directly to a file, this will return the FILEPATH it's set to retrieve to. If HTTPMESSAGE is not set to retrieve directly to a file, the returned FILEPATH will be empty (IsEmpty() will return true).

const STRUTF8& HTTPMESSAGE::GetEscapedRequestURI (  )  const

Get the escaped URI of the request, result is an empty string if it does not exist.

const MILIST<STRUTF8>& HTTPMESSAGE::GetExtraHeaders (  )  const

Get a list of headers that were not parsed.

const char* HTTPMESSAGE::GetHeaderString ( const char *  key  )  const
bool HTTPMESSAGE::GetKeepAlive (  )  const

Returns true if the request had the Connection: Keep-Alive header.

const DATETIME& HTTPMESSAGE::GetMessageTime (  )  const

Returns the time from the HTTP header when the object was retrieved.

Note, this will be the time on the server, not local machine time.

const STRUTF8& HTTPMESSAGE::GetMultiPartBoundary (  )  const

Get the multipart boundary string for inclusion in the Content Type Header.

int HTTPMESSAGE::GetNumBytes (  )  const

Get the number of bytes in the body.

int HTTPMESSAGE::GetNumBytesExpected (  )  const

Get the number of bytes in the body.

If the message has been fully read from the server, this will be the same as GetNumBytes. If the message has only been partly read, GetNumBytes() will return the size read so far and GetNumBytesExpected() will return the expected size.

METHOD HTTPMESSAGE::GetRequestMethod (  )  const
const STRUTF8& HTTPMESSAGE::GetRequestURI (  )  const

Get the URI of the request.

STATUS HTTPMESSAGE::GetStatusCode (  )  const

Get the status code from the HTTP header.

const STRUTF8& HTTPMESSAGE::GetStatusMessage (  )  const

Get the status message from the HTTP header.

static MISTRING HTTPMESSAGE::GetStatusText ( STATUS  status  )  [static]

Get localized text for status.

const DATETIME& HTTPMESSAGE::GetTimeLastModified (  )  const

Get the object's last modified time.

bool HTTPMESSAGE::HasCharEncoding (  )  const

Return true if a CHAR_ENCODING has been set.

bool HTTPMESSAGE::IsCachedResult (  )  const

Set by HTTPCLIENT if the message is from our cache.

bool HTTPMESSAGE::IsDirectToFile (  )  const

Determine if we're writing directly to a file.

bool HTTPMESSAGE::IsHeadRequest (  )  const

Returns true if this is a HEAD request This is just a shortcut because you need it a lot and this is more compact and readable than request.GetRequestMethod() == HTTPMESSAGE::METHOD_HEAD.

HTTPMESSAGE& HTTPMESSAGE::operator= ( const HTTPMESSAGE rhs  ) 

Assignment.

ERRVALUE HTTPMESSAGE::Reserve ( int  size  ) 

Reserve memory for the buffer for the body of the message This also sets the NumBytesExpected().

void HTTPMESSAGE::Reset (  ) 

Reset the message to an initial state.

ERRVALUE HTTPMESSAGE::Resize ( int  size  ) 

Resize the buffer for the body of the message.

void HTTPMESSAGE::SetContentCharEncoding ( const char *  encoding  ) 

Set the content character encoding.

The encoding string is defined by some RFC. (TO DO: look up the RFC).

void HTTPMESSAGE::SetContentCharEncoding ( CHAR_ENCODING  encoding  ) 

Set the content character encoding.

void HTTPMESSAGE::SetContentType ( const char *  ContentType  ) 

Set the value of the Content-Type in the HTTP header.

Parameters:
ContentType any valid MIME type
void HTTPMESSAGE::SetDestFile ( const FILEPATH filepath  ) 

Set the filepath to write the message body to.

Set this before recieving a message if you'd rather have the message body writen directly to a file. To cancel this behaviour, call ClearDestFile();

void HTTPMESSAGE::SetIsCachedResult ( bool  bCachedResult  ) 

Set by HTTPCLIENT if filling in a reply message from the cache.

void HTTPMESSAGE::SetKeepAlive ( bool  bKeepAlive = true  ) 

Set the Connection: header to Keep-Alive.

void HTTPMESSAGE::SetMessageTime ( const DATETIME dts  ) 

Set the Date in the HTTP header.

This is used when recieving a message to record the time in the recieved headers. When sending a message, we always use the current time.

void HTTPMESSAGE::SetRequest ( METHOD  method,
const STRUTF8 uri,
bool  bIsEscaped = false 
)

Setup the message as an HTTP request.

Parameters:
bIsEscaped Pass true if uri is escaped as per RFC1738 (default = false)
void HTTPMESSAGE::SetStatusCode ( STATUS  status  ) 

This is used by a server when sending a reply.

void HTTPMESSAGE::SetStatusMessage ( const char *  msg  ) 

Set the status message for the HTTP header.

This is used by a server when sending a reply. Note, this one might go away. The message should be looked-up from the status code.

void HTTPMESSAGE::SetTimeLastModified ( const DATETIME dts  ) 

Set the Last-Modified in the HTTP header.

This is used by a server when sending a reply.


The documentation for this class was generated from the following file:

Generated on Sun Oct 7 21:33:30 2012 for TNTsdk 2012 by  doxygen 1.6.1