Class to encapuselate an HTTP message. More...
#include <mi32/httpmsg.h>
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.
| enum HTTPMESSAGE::METHOD |
| enum HTTPMESSAGE::STATUS |
HTTP status codes as defined by RFC-2616 1xx Informational 2xx Successful 3xx Redirection 4xx Client error 5xx Server error.
| HTTPMESSAGE::HTTPMESSAGE | ( | ) |
Default constructor.
| HTTPMESSAGE::HTTPMESSAGE | ( | const HTTPMESSAGE & | rhs | ) |
Copy constructor.
| HTTPMESSAGE::~HTTPMESSAGE | ( | ) |
| 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 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.
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
| 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.
| 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.
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.
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.
| 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.
Setup the message as an HTTP request.
| 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.
1.6.1