A simple class to facilitate the creation of HTTP requests. More...
#include <httprequest.h>
Public Member Functions | |
HTTPRequest () | |
Blank constructor. | |
HTTPRequest (const String &ToDecompose) | |
String constructor. More... | |
HTTPRequest (const String &URI, const Network::HTTPRequestMethod Method, const String &Body) | |
Descriptive constructor. | |
~HTTPRequest () | |
Class destructor. | |
String | Compose () const |
Creates a completed Message that can be sent across an HTTP connection. More... | |
Boole | Decompose (const String &Message) |
Populates the members of this class with data from a text HTTP Message. More... | |
Boole | Decompose (StringIterator &CurrIt, const StringIterator EndIt) |
Populates the members of this class with data from a text HTTP Message. More... | |
const String & | GetExpectHeader () const |
Gets the Expect Header. More... | |
const String & | GetFromHeader () const |
Gets the From Header. More... | |
const String & | GetHostHeader () const |
Gets the Host Header. More... | |
Network::HTTPRequestMethod | GetMethod () const |
Gets the method to be used for the request. More... | |
const URI & | GetURI () const |
Gets the URI of the resource being requested. More... | |
const String & | GetUserAgentHeader () const |
Gets the User-Agent Header. More... | |
void | SetExpectHeader (const String &Expect) |
Sets the Expect Header. More... | |
void | SetFromHeader (const String &From) |
Sets the From Header. More... | |
void | SetHostHeader (const String &Host) |
Sets the Host Header. More... | |
void | SetMethod (const Network::HTTPRequestMethod Method) |
Sets the method to be used for the request. More... | |
void | SetURI (const URI &URI) |
Sets the URI of the resource being requested. More... | |
void | SetUserAgentHeader (const String &UserAgent) |
Sets the User-Agent Header. More... | |
![]() | |
const String & | GetBody () const |
Gets the message body containing additional information. More... | |
const String & | GetConnectionHeader () const |
Gets the Connection Header. More... | |
const String & | GetContentLengthHeader () const |
Gets the Content-Length Header. More... | |
const String & | GetContentTypeHeader () const |
Gets the Content-Type Header. More... | |
const String & | GetField (const String &FieldName) const |
Gets a Name-Value pair for a header field in the message. More... | |
UInt16 | GetHTTPMajorVersion () const |
Gets the major version of this message. More... | |
UInt16 | GetHTTPMinorVersion () const |
Gets the minor version of this message. More... | |
const SimpleVersion & | GetHTTPVersion () const |
Gets both the major and minor version of this message. More... | |
Whole | GetMaxFields () const |
Gets how many header fields can be added to this message during parsing. More... | |
Boole | HasField (const String &FieldName) const |
Checks if this message has the named header field. More... | |
void | RemoveAllFields () |
Removes every field from this message. | |
void | RemoveField (const String &FieldName) |
Removes a specific field from this message by name. More... | |
void | SetBody (const String &Body) |
Sets the message body containing additional information. More... | |
void | SetConnectionHeader (const String &Connection) |
Sets the Connection Header. More... | |
void | SetContentLengthHeader (const String &ContentLength) |
Sets the Content-Length Header. More... | |
void | SetContentTypeHeader (const String &ContentType) |
Sets the Content-Type Header. More... | |
void | SetField (const String &FieldName, const String &FieldValue) |
Sets a Name-Value pair for a header field in the message. More... | |
void | SetHTTPMajorVersion (const UInt16 Major) |
Sets the major version of this message. More... | |
void | SetHTTPMinorVersion (const UInt16 Minor) |
Sets the minor version of this message. More... | |
void | SetHTTPVersion (const SimpleVersion &Version) |
Sets both the major and minor version of this message via SimpleVersion. More... | |
void | SetHTTPVersion (const UInt16 Major, const UInt16 Minor) |
Sets both the major and minor version of this message. More... | |
void | SetMaxFields (const Whole MaxFields) |
Sets how many header fields can be added to this message during parsing. More... | |
Static Public Member Functions | |
static String | ConvertRequestMethod (const Network::HTTPRequestMethod Method) |
Converts a HTTPRequestMethod enum value to it's text representation. More... | |
static Network::HTTPRequestMethod | ConvertRequestMethod (const String &Method) |
Converts a text request method to it's HTTPRequestMethod enum value. More... | |
Protected Member Functions | |
Boole | ParseHTTPHeader (StringIterator &CurrIt, const StringIterator EndIt) |
Parses the information contained in the Message Header. More... | |
![]() | |
HTTPMessage () | |
Blank Constructor. | |
HTTPMessage (const UInt16 VerMajor, const UInt16 VerMinor) | |
UInt Version Constructor. | |
HTTPMessage (const SimpleVersion &Version) | |
Version Constructor. | |
virtual | ~HTTPMessage () |
Class destructor. | |
void | AdvanceToNewline (StringIterator &CurrIt, const StringIterator EndIt) |
Convenience method that will ignore and advance passed all characters until one passed the first newline character detected. More... | |
Boole | GetMessageComponent (StringIterator &CurrIt, const StringIterator EndIt, String &Component) |
Extracts all characters from CurrIt until the first space encountered or EndIt, whichever comes first. More... | |
Boole | ParseHTTPFields (StringIterator &CurrIt, const StringIterator EndIt) |
Parses the HTTP fields from a provided string. More... | |
Boole | ParseHTTPVersion (const String &ToParse) |
Parses the HTTP version from a provided string. More... | |
Protected Attributes | |
HTTPRequestMethod | RequestMethod |
The HTTP method to use for the request. More... | |
URI | RequestURI |
The URI of the resource to request. More... | |
![]() | |
Whole | MaxHeaderFields |
The maximum number of allowed header fields in this message. More... | |
String | MessageBody |
The body of the message. More... | |
HeaderFieldContainer | MessageFields |
A container of fields to populate the message header with. More... | |
SimpleVersion | MessageVersion |
The version component for this response. More... | |
Additional Inherited Members | |
![]() | |
typedef HeaderFieldContainer::const_iterator | ConstHeaderFieldIterator |
Const Iterator type for Header Fields in this class. | |
typedef std::vector< HeaderField > | HeaderFieldContainer |
Container type for Header Fields in this class. | |
typedef HeaderFieldContainer::iterator | HeaderFieldIterator |
Iterator type for Header Fields in this class. | |
typedef String::const_iterator | StringIterator |
Convenience typedef for String iterators. | |
A simple class to facilitate the creation of HTTP requests.
Some of the data that can be set is mandatory, some of it is optional. The URI, major and minor versions, as well as the request method to be used are mandatory in all cases. If you are using HTTP 1.1 or higher, then adding a "Host" header field is also mandatory. The host should be the domain name of the server you want to request from. Some request methods make use of the body, most don't. If the body is used then a header field may be required, such as sending a shoutbox message with a POST request, which may require the message be put in the request body, and a "Content-Length" header be supplied with the size of the body. Many more nuances exist, and we can't cover all use cases. So take care when using this class.
Definition at line 61 of file httprequest.h.
Mezzanine::Network::HTTPRequest::HTTPRequest | ( | const String & | ToDecompose | ) |
String constructor.
ToDecompose | The String to construct this request from. |
Definition at line 56 of file httprequest.cpp.
|
virtual |
Creates a completed Message that can be sent across an HTTP connection.
Implements Mezzanine::Network::HTTPMessage.
Definition at line 174 of file httprequest.cpp.
|
static |
Converts a HTTPRequestMethod enum value to it's text representation.
Method | The HTTPRequestMethod enum value to be converted. |
Definition at line 95 of file httprequest.cpp.
|
static |
Converts a text request method to it's HTTPRequestMethod enum value.
Method | The text representation of the request method to be converted. |
Definition at line 121 of file httprequest.cpp.
Populates the members of this class with data from a text HTTP Message.
Message | The String containing the Message to be decomposed. |
Implements Mezzanine::Network::HTTPMessage.
Definition at line 191 of file httprequest.cpp.
|
virtual |
Populates the members of this class with data from a text HTTP Message.
CurrIt | An iterator at the start of the range to be parsed. |
EndIt | An iterator at the end of the range to be parsed. Parsing may or may not reach this point. |
Implements Mezzanine::Network::HTTPMessage.
Definition at line 197 of file httprequest.cpp.
const String & Mezzanine::Network::HTTPRequest::GetExpectHeader | ( | ) | const |
Gets the Expect Header.
Definition at line 237 of file httprequest.cpp.
const String & Mezzanine::Network::HTTPRequest::GetFromHeader | ( | ) | const |
Gets the From Header.
Definition at line 243 of file httprequest.cpp.
const String & Mezzanine::Network::HTTPRequest::GetHostHeader | ( | ) | const |
Gets the Host Header.
Definition at line 249 of file httprequest.cpp.
Network::HTTPRequestMethod Mezzanine::Network::HTTPRequest::GetMethod | ( | ) | const |
Gets the method to be used for the request.
Definition at line 228 of file httprequest.cpp.
const URI & Mezzanine::Network::HTTPRequest::GetURI | ( | ) | const |
Gets the URI of the resource being requested.
Definition at line 222 of file httprequest.cpp.
const String & Mezzanine::Network::HTTPRequest::GetUserAgentHeader | ( | ) | const |
Gets the User-Agent Header.
Definition at line 255 of file httprequest.cpp.
|
protectedvirtual |
Parses the information contained in the Message Header.
CurrIt | An iterator to the current character being processed in the string being parsed. |
EndIt | An iterator to the last character in the string to be parsed. |
Implements Mezzanine::Network::HTTPMessage.
Definition at line 67 of file httprequest.cpp.
void Mezzanine::Network::HTTPRequest::SetExpectHeader | ( | const String & | Expect | ) |
Sets the Expect Header.
Expect | Used to describe to the server one or more expectations being made on it by the client. |
Definition at line 234 of file httprequest.cpp.
void Mezzanine::Network::HTTPRequest::SetFromHeader | ( | const String & | From | ) |
Sets the From Header.
From | Contains an email address that uniquely identifies the sender of the request. |
Definition at line 240 of file httprequest.cpp.
void Mezzanine::Network::HTTPRequest::SetHostHeader | ( | const String & | Host | ) |
Sets the Host Header.
Host | The URI-Authority of the host to be connected to. |
Definition at line 246 of file httprequest.cpp.
void Mezzanine::Network::HTTPRequest::SetMethod | ( | const Network::HTTPRequestMethod | Method | ) |
Sets the method to be used for the request.
Method | The HTTP method to use for the request. Initial Value: HRM_GET. |
Definition at line 225 of file httprequest.cpp.
void Mezzanine::Network::HTTPRequest::SetURI | ( | const URI & | URI | ) |
Sets the URI of the resource being requested.
Definition at line 219 of file httprequest.cpp.
void Mezzanine::Network::HTTPRequest::SetUserAgentHeader | ( | const String & | UserAgent | ) |
Sets the User-Agent Header.
UserAgent | The name of the platform/software being used to generate this request. |
Definition at line 252 of file httprequest.cpp.
|
protected |
The HTTP method to use for the request.
Definition at line 66 of file httprequest.h.
|
protected |
The URI of the resource to request.
Definition at line 69 of file httprequest.h.