Add HTTPHeaders::build_map

This commit is contained in:
Vinnie Falco
2014-07-24 10:33:43 -07:00
parent 2f5fb1e68e
commit 87351c8a0c
2 changed files with 23 additions and 1 deletions

View File

@@ -17,6 +17,8 @@
*/
//==============================================================================
#include <algorithm>
namespace beast {
HTTPHeaders::HTTPHeaders ()
@@ -86,4 +88,20 @@ String HTTPHeaders::toString () const
return s;
}
std::map <std::string, std::string>
HTTPHeaders::build_map() const
{
std::map <std::string, std::string> c;
auto const& k (m_fields.getAllKeys());
auto const& v (m_fields.getAllValues());
for (std::size_t i = 0; i < m_fields.size(); ++i)
{
auto key (k[i].toStdString());
auto const value (v[i].toStdString());
std::transform (key.begin(), key.end(), key.begin(), ::tolower);
c[key] = value;
}
return c;
}
}

View File

@@ -21,8 +21,8 @@
#define BEAST_ASIO_HTTPHEADERS_H_INCLUDED
#include <beast/module/asio/http/HTTPField.h>
#include <beast/module/core/text/StringPairArray.h>
#include <map>
namespace beast {
@@ -70,6 +70,10 @@ public:
/** Outputs all the headers into one string. */
String toString () const;
// VFALCO HACK to present the headers in a useful format
std::map <std::string, std::string>
build_map() const;
private:
StringPairArray m_fields;
};