From 986cce63357649bf158a375b6a873ca130144119 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 16 Mar 2013 01:09:34 -0700 Subject: [PATCH] Fix case sensitive header issues. --- src/cpp/websocketpp/src/http/parser.hpp | 22 +++++++++++++++------- src/cpp/websocketpp/src/roles/server.hpp | 2 -- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/cpp/websocketpp/src/http/parser.hpp b/src/cpp/websocketpp/src/http/parser.hpp index f79a3753cd..e6b2636a3a 100644 --- a/src/cpp/websocketpp/src/http/parser.hpp +++ b/src/cpp/websocketpp/src/http/parser.hpp @@ -50,6 +50,14 @@ namespace parser { typedef std::map header_list; +static std::string tolower(const std::string& in) +{ + std::string out = in; + for (int i = 0; i < out.size(); ++i) + if (isupper(out[i])) + out[i] = ::tolower(out[i]); + return out; +} class parser { public: @@ -69,7 +77,7 @@ public: } std::string header(const std::string& key) const { - header_list::const_iterator h = m_headers.find(key); + header_list::const_iterator h = m_headers.find(tolower(key)); if (h == m_headers.end()) { return ""; @@ -80,21 +88,21 @@ public: // multiple calls to add header will result in values aggregating. // use replace_header if you do not want this behavior. - void add_header(const std::string &key,const std::string &val) { + void add_header(const std::string &key, const std::string &val) { // TODO: prevent use of reserved headers? if (this->header(key) == "") { - m_headers[key] = val; + m_headers[tolower(key)] = val; } else { - m_headers[key] += ", " + val; + m_headers[tolower(key)] += ", " + val; } } - void replace_header(const std::string &key,const std::string &val) { - m_headers[key] = val; + void replace_header(const std::string &key, const std::string &val) { + m_headers[tolower(key)] = val; } void remove_header(const std::string &key) { - m_headers.erase(key); + m_headers.erase(tolower(key)); } protected: bool parse_headers(std::istream& s) { diff --git a/src/cpp/websocketpp/src/roles/server.hpp b/src/cpp/websocketpp/src/roles/server.hpp index f77397d55b..f45f51e382 100644 --- a/src/cpp/websocketpp/src/roles/server.hpp +++ b/src/cpp/websocketpp/src/roles/server.hpp @@ -620,8 +620,6 @@ void server::connection::handle_read_request( //m_endpoint.m_alog.at(log::alevel::DEBUG_HANDSHAKE) << m_request.raw() << log::endl; std::string h = m_request.header("Upgrade"); - if (h.empty()) - h = m_request.header("upgrade"); if (boost::ifind_first(h,"websocket")) { // Version is stored in the Sec-WebSocket-Version header for all // versions after draft Hybi 00/Hixie 76. The absense of a version