Conventional capitalization when writing headers, leniency when reading.

This commit is contained in:
Eric Lombrozo
2013-07-11 18:36:40 +02:00
parent 664c4a28ea
commit c73e6ba3e2

View File

@@ -83,7 +83,12 @@ public:
}
std::string header(const std::string& key) const {
header_list::const_iterator h = m_headers.find(tolower(key));
header_list::const_iterator h = m_headers.find(key);
if (h != m_headers.end()) {
return h->second;
}
h = m_headers.find(tolower(key));
if (h == m_headers.end()) {
return "";
@@ -97,18 +102,18 @@ public:
void add_header(const std::string &key, const std::string &val) {
// TODO: prevent use of reserved headers?
if (this->header(key) == "") {
m_headers[tolower(key)] = val;
m_headers[key] = val;
} else {
m_headers[tolower(key)] += ", " + val;
m_headers[key] += ", " + val;
}
}
void replace_header(const std::string &key, const std::string &val) {
m_headers[tolower(key)] = val;
m_headers[key] = val;
}
void remove_header(const std::string &key) {
m_headers.erase(tolower(key));
m_headers.erase(key);
}
protected:
bool parse_headers(std::istream& s) {