diff --git a/libi2pd/HTTP.cpp b/libi2pd/HTTP.cpp index e04e8ca2..08b0a8e4 100644 --- a/libi2pd/HTTP.cpp +++ b/libi2pd/HTTP.cpp @@ -372,7 +372,7 @@ namespace http void HTTPReq::UpdateHeader (const std::string& name, const std::string& value) { for (auto& it : headers) - if (it.first == name) + if (boost::iequals(it.first, name)) { it.second = value; break; @@ -383,7 +383,7 @@ namespace http { for (auto it = headers.begin (); it != headers.end ();) { - if (!it->first.compare(0, name.length (), name) && it->first != exempt) + if (boost::istarts_with(it->first, name) && !boost::iequals(it->first, exempt)) it = headers.erase (it); else it++; @@ -393,7 +393,7 @@ namespace http std::string HTTPReq::GetHeader (std::string_view name) const { for (auto& it : headers) - if (it.first == name) + if (boost::iequals(it.first, name)) return it.second; return ""; } @@ -402,7 +402,7 @@ namespace http { size_t num = 0; for (auto& it : headers) - if (it.first == name) num++; + if (boost::iequals(it.first, name)) num++; return num; } diff --git a/libi2pd/HTTP.h b/libi2pd/HTTP.h index 3af31210..11e9df6e 100644 --- a/libi2pd/HTTP.h +++ b/libi2pd/HTTP.h @@ -16,6 +16,7 @@ #include #include #include +#include namespace i2p { @@ -24,6 +25,17 @@ namespace http constexpr std::string_view CRLF = "\r\n"; /**< HTTP line terminator */ constexpr std::string_view HTTP_EOH = "\r\n\r\n"; /**< HTTP end-of-headers mark */ + // case-insensitive comparator for HTTP header names (RFC 7230) + struct CaseInsensitiveLess + { + using is_transparent = void; + + bool operator() (std::string_view a, std::string_view b) const + { + return boost::ilexicographical_compare(a, b); + } + }; + struct URL { std::string schema; @@ -66,7 +78,7 @@ namespace http struct HTTPMsg { - std::map headers; + std::map headers; void add_header(const char *name, const std::string & value, bool replace = false); void add_header(const char *name, const char *value, bool replace = false);