Spinning Topp Logo BlackTopp Studios
inc
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Mezzanine::Network::HTTPRequest Class Reference

A simple class to facilitate the creation of HTTP requests. More...

#include <httprequest.h>

+ Inheritance diagram for Mezzanine::Network::HTTPRequest:
+ Collaboration diagram for Mezzanine::Network::HTTPRequest:

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 StringGetExpectHeader () const
 Gets the Expect Header. More...
 
const StringGetFromHeader () const
 Gets the From Header. More...
 
const StringGetHostHeader () const
 Gets the Host Header. More...
 
Network::HTTPRequestMethod GetMethod () const
 Gets the method to be used for the request. More...
 
const URIGetURI () const
 Gets the URI of the resource being requested. More...
 
const StringGetUserAgentHeader () 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...
 
- Public Member Functions inherited from Mezzanine::Network::HTTPMessage
const StringGetBody () const
 Gets the message body containing additional information. More...
 
const StringGetConnectionHeader () const
 Gets the Connection Header. More...
 
const StringGetContentLengthHeader () const
 Gets the Content-Length Header. More...
 
const StringGetContentTypeHeader () const
 Gets the Content-Type Header. More...
 
const StringGetField (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 SimpleVersionGetHTTPVersion () 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...
 
- Protected Member Functions inherited from Mezzanine::Network::HTTPMessage
 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...
 
- Protected Attributes inherited from Mezzanine::Network::HTTPMessage
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

- Public Types inherited from Mezzanine::Network::HTTPMessage
typedef HeaderFieldContainer::const_iterator ConstHeaderFieldIterator
 Const Iterator type for Header Fields in this class.
 
typedef std::vector< HeaderFieldHeaderFieldContainer
 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.
 

Detailed Description

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.

Constructor & Destructor Documentation

Mezzanine::Network::HTTPRequest::HTTPRequest ( const String ToDecompose)

String constructor.

Parameters
ToDecomposeThe String to construct this request from.
Remarks
For normal operation this constructor should seldom be used, since this class is intended to aid in building the string.

Definition at line 56 of file httprequest.cpp.

Member Function Documentation

String Mezzanine::Network::HTTPRequest::Compose ( ) const
virtual

Creates a completed Message that can be sent across an HTTP connection.

Returns
Returns a String containing the generated Message.

Implements Mezzanine::Network::HTTPMessage.

Definition at line 174 of file httprequest.cpp.

String Mezzanine::Network::HTTPRequest::ConvertRequestMethod ( const Network::HTTPRequestMethod  Method)
static

Converts a HTTPRequestMethod enum value to it's text representation.

Parameters
MethodThe HTTPRequestMethod enum value to be converted.
Returns
Returns a String containing the converted enum value.

Definition at line 95 of file httprequest.cpp.

Network::HTTPRequestMethod Mezzanine::Network::HTTPRequest::ConvertRequestMethod ( const String Method)
static

Converts a text request method to it's HTTPRequestMethod enum value.

Parameters
MethodThe text representation of the request method to be converted.
Returns
Returns a HTTPRequestMethod enum value representing the converted String.

Definition at line 121 of file httprequest.cpp.

Boole Mezzanine::Network::HTTPRequest::Decompose ( const String Message)
virtual

Populates the members of this class with data from a text HTTP Message.

Parameters
MessageThe String containing the Message to be decomposed.
Returns
Returns true if the String was successfully decomposed.
Warning
A request can be partially decomposed when it fails and have that data saved to members of this class. For that reason you should only utilize the data in this class if the decompose was successful, or completely re-written.

Implements Mezzanine::Network::HTTPMessage.

Definition at line 191 of file httprequest.cpp.

Boole Mezzanine::Network::HTTPRequest::Decompose ( StringIterator CurrIt,
const StringIterator  EndIt 
)
virtual

Populates the members of this class with data from a text HTTP Message.

Parameters
CurrItAn iterator at the start of the range to be parsed.
EndItAn iterator at the end of the range to be parsed. Parsing may or may not reach this point.
Returns
Returns true if the String was successfully decomposed.
Warning
A request can be partially decomposed when it fails and have that data saved to members of this class. For that reason you should only utilize the data in this class if the decompose was successful, or completely re-written.

Implements Mezzanine::Network::HTTPMessage.

Definition at line 197 of file httprequest.cpp.

const String & Mezzanine::Network::HTTPRequest::GetExpectHeader ( ) const

Gets the Expect Header.

Returns
Returns a String containing one or more expectations being made on the server by the client.

Definition at line 237 of file httprequest.cpp.

const String & Mezzanine::Network::HTTPRequest::GetFromHeader ( ) const

Gets the From Header.

Returns
Returns a String containing an email address that uniquely identifies the sender of the request.

Definition at line 243 of file httprequest.cpp.

const String & Mezzanine::Network::HTTPRequest::GetHostHeader ( ) const

Gets the Host Header.

Returns
Returns a String containing the URI-Authority of the host to be connected to, or blank if the field is not set.

Definition at line 249 of file httprequest.cpp.

Network::HTTPRequestMethod Mezzanine::Network::HTTPRequest::GetMethod ( ) const

Gets the method to be used for the request.

Returns
Returns a HTTPRequestMethod enum value of the request method to be used.

Definition at line 228 of file httprequest.cpp.

const URI & Mezzanine::Network::HTTPRequest::GetURI ( ) const

Gets the URI of the resource being requested.

Returns
Returns a String containing the Uniform Resource Identifier 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.

Returns
Returns a String containing the name of the platform/software being used to generate this request.

Definition at line 255 of file httprequest.cpp.

Boole Mezzanine::Network::HTTPRequest::ParseHTTPHeader ( StringIterator CurrIt,
const StringIterator  EndIt 
)
protectedvirtual

Parses the information contained in the Message Header.

Parameters
CurrItAn iterator to the current character being processed in the string being parsed.
EndItAn iterator to the last character in the string to be parsed.
Returns
Returns true if the parse was successful, false if it failed.

Implements Mezzanine::Network::HTTPMessage.

Definition at line 67 of file httprequest.cpp.

void Mezzanine::Network::HTTPRequest::SetExpectHeader ( const String Expect)

Sets the Expect Header.

Remarks
An optional header that most commonly is used when the expectation is "100-continue". When that expectation is set a partial request (without a body) can be sent to the HTTP server and will check the headers to see if anything is malformed there. If nothing is it will succeed and the client can then send a full request with the body. Useful for requests with very large bodies.
Parameters
ExpectUsed 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.

Remarks
This field is entirely optional. Some smaller web services can make use of this however.
Parameters
FromContains 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.

Remarks
This header is required for all requests being made via HTTP 1.1 and up. It is useful for servers when resolving specific hosts behind proxies.
Parameters
HostThe 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.

Parameters
MethodThe 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.

Parameters
URIThe Uniform Resource Identifier of the resource to request.

Definition at line 219 of file httprequest.cpp.

void Mezzanine::Network::HTTPRequest::SetUserAgentHeader ( const String UserAgent)

Sets the User-Agent Header.

Remarks
An optional header used to provide slightly more context about what the requester is running.
Parameters
UserAgentThe name of the platform/software being used to generate this request.

Definition at line 252 of file httprequest.cpp.

Member Data Documentation

HTTPRequestMethod Mezzanine::Network::HTTPRequest::RequestMethod
protected

The HTTP method to use for the request.

Definition at line 66 of file httprequest.h.

URI Mezzanine::Network::HTTPRequest::RequestURI
protected

The URI of the resource to request.

Definition at line 69 of file httprequest.h.


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