41 #ifndef _networkhttpmessage_cpp
42 #define _networkhttpmessage_cpp
44 #include "Network/httpmessage.h"
46 #include "stringtool.h"
59 Mezzanine::Boole LowerCaseCompare(const Mezzanine::Char8 First, const Mezzanine::Char8 Second)
60 { return ( tolower(First) < tolower(Second) ); }
66 Mezzanine::Boole HeaderFieldCompare(const Mezzanine::Network::HeaderField& First, const Mezzanine::Network::HeaderField& Second)
67 { return std::lexicographical_compare(First.HeaderName.begin(),First.HeaderName.end(),Second.HeaderName.begin(),Second.HeaderName.end(),LowerCaseCompare); }
76 if( First.size() != Second.size() ) {
82 if( tolower( First[Index] ) != tolower( Second[Index] ) ) {
101 MaxHeaderFields(100),
102 MessageVersion(VerMajor,VerMinor)
106 MaxHeaderFields(100),
107 MessageVersion(Version)
115 if( ToParse.length() == 8 &&
116 ToParse.at(6) ==
'.' &&
129 Boole PreColon =
true;
147 this->
SetField(FieldName,FieldValue);
150 if( *(CurrIt + 1) ==
'\r' && *(CurrIt + 2) ==
'\n' ) {
161 FieldValue.push_back( *CurrIt );
167 if( PreColon ) FieldName.push_back( *CurrIt );
168 else FieldValue.push_back( *CurrIt );
179 while( (*CurrIt) !=
' ' && (*CurrIt) !=
'\r' && CurrIt != EndIt )
181 Component.push_back( *CurrIt );
185 if( CurrIt != EndIt ) {
187 if( (*CurrIt) ==
'\r' && *(CurrIt + 1) ==
'\n' ) {
190 }
else if( (*CurrIt) ==
' ' ) {
199 while( CurrIt != EndIt )
202 if( (*CurrIt) ==
'\n' ) {
255 if( IsEqualCaseInsensitive( (*FieldIt).HeaderName, FieldName ) ) {
256 (*FieldIt).HeaderValue = FieldValue;
274 if( IsEqualCaseInsensitive( (*FieldIt).HeaderName, FieldName ) ) {
275 return (*FieldIt).HeaderValue;
289 if( IsEqualCaseInsensitive( (*FieldIt).HeaderName, FieldName ) ) {
306 if( IsEqualCaseInsensitive( (*FieldIt).HeaderName, FieldName ) ) {
322 { this->
SetField(
"Connection",Connection); }
325 {
return this->
GetField(
"Connection"); }
328 { this->
SetField(
"Content-Length",ContentLength); }
331 {
return this->
GetField(
"Content-Length"); }
334 { this->
SetField(
"Content-Type",ContentType); }
337 {
return this->
GetField(
"Content-Type"); }
A base class for the state of a connection made between peers.
String::const_iterator StringIterator
Convenience typedef for String iterators.
Boole HasField(const String &FieldName) const
Checks if this message has the named header field.
void RemoveField(const String &FieldName)
Removes a specific field from this message by name.
Boole ParseHTTPFields(StringIterator &CurrIt, const StringIterator EndIt)
Parses the HTTP fields from a provided string.
bool Boole
Generally acts a single bit, true or false.
const String & GetConnectionHeader() const
Gets the Connection Header.
UInt16 GetHTTPMinorVersion() const
Gets the minor version of this message.
UInt16 Major
The Major component of the version to be expressed.
const String & GetContentTypeHeader() const
Gets the Content-Type Header.
const String & GetField(const String &FieldName) const
Gets a Name-Value pair for a header field in the message.
virtual ~HTTPMessage()
Class destructor.
void RemoveAllFields()
Removes every field from this message.
const SimpleVersion & GetHTTPVersion() const
Gets both the major and minor version of this message.
SimpleVersion MessageVersion
The version component for this response.
UInt16 Minor
The Minor component of the version to be expressed.
uint16_t UInt16
An 16-bit unsigned integer.
void SetContentLengthHeader(const String &ContentLength)
Sets the Content-Length Header.
Boole GetMessageComponent(StringIterator &CurrIt, const StringIterator EndIt, String &Component)
Extracts all characters from CurrIt until the first space encountered or EndIt, whichever comes first...
void SetBody(const String &Body)
Sets the message body containing additional information.
HeaderFieldContainer::const_iterator ConstHeaderFieldIterator
Const Iterator type for Header Fields in this class.
A very basic class for expressing an API or syntax version.
const String & GetContentLengthHeader() const
Gets the Content-Length Header.
UInt16 GetHTTPMajorVersion() const
Gets the major version of this message.
void SetField(const String &FieldName, const String &FieldValue)
Sets a Name-Value pair for a header field in the message.
Whole GetMaxFields() const
Gets how many header fields can be added to this message during parsing.
void SetHTTPVersion(const SimpleVersion &Version)
Sets both the major and minor version of this message via SimpleVersion.
Whole MaxHeaderFields
The maximum number of allowed header fields in this message.
void SetConnectionHeader(const String &Connection)
Sets the Connection Header.
Boole ParseHTTPVersion(const String &ToParse)
Parses the HTTP version from a provided string.
The bulk of the engine components go in this namspace.
HeaderFieldContainer MessageFields
A container of fields to populate the message header with.
void SetMaxFields(const Whole MaxFields)
Sets how many header fields can be added to this message during parsing.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
String MessageBody
The body of the message.
HeaderFieldContainer::iterator HeaderFieldIterator
Iterator type for Header Fields in this class.
void SetHTTPMinorVersion(const UInt16 Minor)
Sets the minor version of this message.
void SetContentTypeHeader(const String &ContentType)
Sets the Content-Type Header.
const String & GetBody() const
Gets the message body containing additional information.
std::string String
A datatype used to a series of characters.
void SetHTTPMajorVersion(const UInt16 Major)
Sets the major version of this message.
void AdvanceToNewline(StringIterator &CurrIt, const StringIterator EndIt)
Convenience method that will ignore and advance passed all characters until one passed the first newl...
HTTPMessage()
Blank Constructor.