Fix case sensitive header issues.

This commit is contained in:
JoelKatz
2013-03-16 01:09:34 -07:00
parent 51320d8746
commit 986cce6335
2 changed files with 15 additions and 9 deletions

View File

@@ -50,6 +50,14 @@ namespace parser {
typedef std::map<std::string,std::string> 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) {

View File

@@ -620,8 +620,6 @@ void server<endpoint>::connection<connection_type>::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