diff options
-rw-r--r-- | includes/BString.h | 3 | ||||
-rw-r--r-- | src/BString.cc | 20 | ||||
-rw-r--r-- | src/HttpServer.cc | 25 |
3 files changed, 40 insertions, 8 deletions
diff --git a/includes/BString.h b/includes/BString.h index 89f1d9f..8242af8 100644 --- a/includes/BString.h +++ b/includes/BString.h @@ -8,6 +8,7 @@ #endif #include <stdlib.h> #include <string> +#include <vector> namespace Balau { @@ -44,6 +45,8 @@ class String : private std::string { int to_int(int base = 0) const { return strtol(to_charp(), NULL, base); } double to_double() const { return strtod(to_charp(), NULL); } + typedef std::vector<String> List; + List split(char c); size_t strlen() const { return std::string::length(); } ssize_t strchr(char c, size_t begin = 0) const { return find(c, begin); } diff --git a/src/BString.cc b/src/BString.cc index 262a9fa..74156bf 100644 --- a/src/BString.cc +++ b/src/BString.cc @@ -111,3 +111,23 @@ Balau::String & Balau::String::do_iconv(const char * from, const char * _to) { return *this; } + +Balau::String::List Balau::String::split(char c) { + char * d, * p, * f; + List r; + + d = p = strdup(); + + while (true) { + f = ::strchr(p, c); + if (!f) + break; + *f = 0; + r.push_back(p); + p = f + 1; + } + + r.push_back(p); + free(d); + return r; +} diff --git a/src/HttpServer.cc b/src/HttpServer.cc index d99e1ea..3da8cf5 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -254,14 +254,23 @@ bool Balau::HttpWorker::handleClient() { Http::StringMap::iterator i = httpHeaders.find("Connection"); if (i != httpHeaders.end()) { - if (i->second == "close") { - persistent = false; - } else if (i->second == "keep-alive") { - persistent = true; - } else { - Balau::Printer::elog(Balau::E_HTTPSERVER, "%s has an improper Connection HTTP header", m_name.to_charp()); - send400(); - return false; + String conn = i->second; + String::List connVals = conn.split(','); + bool gotOne = false; + for (String::List::iterator j = connVals.begin(); j != connVals.end(); j++) { + if ((*j == "close") && (!gotOne)) { + gotOne = true; + persistent = false; + } else if ((*j == "keep-alive") && (!gotOne)) { + gotOne = true; + persistent = true; + } else if (*j == "TE") { + Balau::Printer::elog(Balau::E_HTTPSERVER, "%s got the 'TE' connection marker (which is still unknown)", m_name.to_charp()); + } else { + Balau::Printer::elog(Balau::E_HTTPSERVER, "%s has an improper Connection HTTP header (%s)", m_name.to_charp(), j->to_charp()); + send400(); + return false; + } } } else { persistent = true; |