summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@yahoo.com>2015-05-28 21:54:10 +0200
committerJoel Klinghed <the_jk@yahoo.com>2015-05-28 21:54:57 +0200
commitfb659a41cfe5523c62fd6993acddab120ccb0758 (patch)
treede4f047509e878864a114a0fe62d00f555a00dda
parente0e50d64326887ed1403e90479244d9baba972d1 (diff)
Fix some mistakes
-rw-r--r--src/cgi.cc15
-rw-r--r--src/header_parser.cc12
-rw-r--r--test/test-header-parser.cc2
3 files changed, 17 insertions, 12 deletions
diff --git a/src/cgi.cc b/src/cgi.cc
index edca4fe..5f86aac 100644
--- a/src/cgi.cc
+++ b/src/cgi.cc
@@ -4,7 +4,6 @@
#if HAVE_FASTCGI
#include <fcgio.h>
#endif
-#include <iostream>
#include <memory>
#include "cgi.hh"
@@ -76,11 +75,11 @@ public:
auto p = getparam("REQUEST_METHOD");
if (p) {
auto method = ascii_tolower(p);
- if (method.compare("GET") == 0) return GET;
- if (method.compare("POST") == 0) return POST;
- if (method.compare("HEAD") == 0) return HEAD;
- if (method.compare("PUT") == 0) return PUT;
- if (method.compare("TRACE") == 0) return TRACE;
+ if (method.compare("get") == 0) return GET;
+ if (method.compare("post") == 0) return POST;
+ if (method.compare("head") == 0) return HEAD;
+ if (method.compare("put") == 0) return PUT;
+ if (method.compare("trace") == 0) return TRACE;
}
return UNKNOWN;
}
@@ -91,6 +90,10 @@ public:
}
protected:
+ CGIImpl()
+ : have_post_data_(false) {
+ }
+
virtual const char* getparam(const char* name) = 0;
private:
diff --git a/src/header_parser.cc b/src/header_parser.cc
index 163d65f..8d17351 100644
--- a/src/header_parser.cc
+++ b/src/header_parser.cc
@@ -8,6 +8,7 @@ namespace {
bool read_token(std::string::const_iterator* begin,
const std::string::const_iterator& end,
+ bool to_lower,
std::string* out) {
auto i = *begin;
if (i == end) return false;
@@ -15,12 +16,13 @@ bool read_token(std::string::const_iterator* begin,
out->clear();
do {
if ((*i >= '^' && *i <= 'z') ||
+ (!to_lower && *i >= 'A' && *i <= 'Z') ||
(*i >= '0' && *i <= '9') ||
(*i >= '#' && *i <= '\'') ||
*i == '!' || *i == '*' || *i == '+' || *i == '-' || *i == '.' ||
*i == '|' || *i == '~') {
++i;
- } else if (*i >= 'A' && *i <= 'Z') {
+ } else if (to_lower && *i >= 'A' && *i <= 'Z') {
out->insert(out->end(), last, i);
out->push_back('a' + *i - 'A');
last = ++i;
@@ -73,13 +75,13 @@ bool HeaderParser::parse(const std::string& in, std::string* token,
std::map<std::string, std::string>* parameters) {
auto i = in.begin();
while (i != in.end() && (*i == ' ' || *i == '\t')) ++i;
- if (!read_token(&i, in.end(), token)) return false;
+ if (!read_token(&i, in.end(), true, token)) return false;
while (true) {
if (i == in.end() || *i != '/') break;
std::string tmp;
token->push_back('/');
++i;
- if (!read_token(&i, in.end(), &tmp)) return false;
+ if (!read_token(&i, in.end(), true, &tmp)) return false;
token->append(tmp);
}
if (parameters) parameters->clear();
@@ -91,13 +93,13 @@ bool HeaderParser::parse(const std::string& in, std::string* token,
while (i != in.end() && (*i == ' ' || *i == '\t')) ++i;
if (i == in.end()) return false;
std::string key, value;
- if (!read_token(&i, in.end(), &key)) return false;
+ if (!read_token(&i, in.end(), true, &key)) return false;
if (i == in.end() || *i != '=') return false;
++i;
if (i != in.end() && *i == '"') {
if (!read_quoted(&i, in.end(), &value)) return false;
} else {
- if (!read_token(&i, in.end(), &value)) return false;
+ if (!read_token(&i, in.end(), false, &value)) return false;
}
if (parameters) (*parameters)[key] = value;
}
diff --git a/test/test-header-parser.cc b/test/test-header-parser.cc
index c2b78f7..03e3e83 100644
--- a/test/test-header-parser.cc
+++ b/test/test-header-parser.cc
@@ -66,7 +66,7 @@ int main() {
tot++; if (test("text/html;charset=utf-8",
"text/html", "charset", "utf-8", NULL)) ok++;
tot++; if (test("text/html;charset=UTF-8",
- "text/html", "charset", "utf-8", NULL)) ok++;
+ "text/html", "charset", "UTF-8", NULL)) ok++;
tot++; if (test("Text/HTML;Charset=\"utf-8\"",
"text/html", "charset", "utf-8", NULL)) ok++;
tot++; if (test("text/html; charset=\"utf-8\"",