+#include <unordered_map>
+#include <vector>
+
+// Locale-unaware tolower(); matches RFC 2616 no matter what the locale is set to.
+static inline char ascii_tolower(const char ch)
+{
+ if (ch >= 'A' && ch <= 'Z') {
+ return ch + 'a' - 'A';
+ } else {
+ return ch;
+ }
+}
+
+// Case-insensitive header comparison and hashing.
+struct HTTPEqual {
+ bool operator() (const std::string &a, const std::string &b) const
+ {
+ return a.size() == b.size() &&
+ std::equal(
+ begin(a), end(a), begin(b),
+ [](char a, char b) {
+ return ascii_tolower(a) == ascii_tolower(b);
+ });
+ }
+};
+struct HTTPHash {
+ size_t operator() (const std::string &s) const
+ {
+ std::string s_low = s;
+ for (char &ch : s_low) { ch = ascii_tolower(ch); }
+ return std::hash<std::string>() (s_low);
+ }
+};
+using HTTPHeaderMultimap = std::unordered_multimap<std::string, std::string, HTTPHash, HTTPEqual>;