HTTP parsing bug fixes, added tests

Fixed HTTP request parse failing if the URI was too short. 

Fixed HTTP parser not converting POST/GET data to lowercase before storing it, making post and get data which contained capitals impossible to access.
This commit is contained in:
Fred Nicolson
2018-01-26 13:18:45 +00:00
parent 7bab41ed9b
commit ad847f0052
3 changed files with 34 additions and 6 deletions
+26
View File
@@ -185,4 +185,30 @@ TEST(HttpRequestTest, partial_parse)
ASSERT_EQ(request.get_type(), fr::Http::Get);
ASSERT_EQ(request.header("content-type"), "application/x-www-form-urlencoded");
ASSERT_EQ(request.header("Cache-Control"), "no-cache");
}
TEST(HttpRequestTest, awkward_parse)
{
std::string request_data = ""
"POST /my/url? HTTP/1.1\n"
"\n"
"Test=bob\n"
"\n";
fr::HttpRequest request;
ASSERT_EQ(request.parse(request_data.c_str(), request_data.size()), fr::Socket::Success);
ASSERT_EQ(request.get_uri(), "/my/url");
ASSERT_EQ(request.post("Test"), "bob");
}
TEST(HttpRequestTest, awkward_parse2)
{
std::string request_data = "POST /my/url?Bob=10 HTTP/1.1\n"
"\n"
"Test=bob";
fr::HttpRequest request;
ASSERT_EQ(request.parse(request_data.c_str(), request_data.size()), fr::Socket::Success);
ASSERT_EQ(request.get_uri(), "/my/url");
ASSERT_EQ(request.get("Bob"), "10");
ASSERT_EQ(request.post("Test"), "bob");
}