Add HTTPMessage::toString and family

This commit is contained in:
Vinnie Falco
2013-09-11 18:24:40 -07:00
parent ee728e3dbc
commit 057344e1af
6 changed files with 38 additions and 0 deletions

View File

@@ -72,3 +72,15 @@ String HTTPHeaders::operator[] (String const& field) const
{
return get (field);
}
String HTTPHeaders::toString () const
{
String s;
for (int i = 0; i < m_fields.size (); ++i)
{
HTTPField const field (at(i));
s << field.name() << ": " << field.value() << newLine;
}
return s;
}

View File

@@ -61,6 +61,9 @@ public:
String operator[] (String const& field) const;
/** @} */
/** Outputs all the headers into one string. */
String toString () const;
private:
StringPairArray m_fields;
};

View File

@@ -40,3 +40,11 @@ ContentBodyBuffer const& HTTPMessage::body () const
{
return m_body;
}
String HTTPMessage::toString () const
{
String s;
s << "HTTP " << version().toString() << newLine;
s << m_headers.toString ();
return s;
}

View File

@@ -51,6 +51,9 @@ public:
/** Returns the content-body. */
ContentBodyBuffer const& body () const;
/** Outputs all the HTTPMessage data excluding the body into a string. */
String toString () const;
private:
HTTPVersion m_version;
HTTPHeaders m_headers;

View File

@@ -31,3 +31,12 @@ unsigned short HTTPResponse::status () const
{
return m_status;
}
String HTTPResponse::toString () const
{
String s;
s << "Status: " << String::fromNumber (status ()) << newLine;
s << this->HTTPMessage::toString ();
return s;
}

View File

@@ -35,6 +35,9 @@ public:
unsigned short status () const;
/** Convert the response into a string, excluding the body. */
String toString () const;
private:
unsigned short m_status;
};