diff --git a/include/frnetlib/Http.h b/include/frnetlib/Http.h index b8b1a18..17d6a77 100644 --- a/include/frnetlib/Http.h +++ b/include/frnetlib/Http.h @@ -139,7 +139,7 @@ namespace fr * @param key The name of the GET variable * @return A reference to the GET variable */ - std::string &get(const std::string &key); + std::string &get(std::string key); /*! * Returns a reference to a POST variable. @@ -150,7 +150,7 @@ namespace fr * @param key The name of the POST variable * @return A reference to the POST variable */ - std::string &post(const std::string &key); + std::string &post(std::string key); /*! * Returns a reference to a header. @@ -161,7 +161,7 @@ namespace fr * @param key The name of the header * @return A reference to the header */ - std::string &header(const std::string &key); + std::string &header(std::string key); /*! @@ -170,7 +170,7 @@ namespace fr * @param key The name of the GET variable * @return True if it does. False otherwise. */ - bool get_exists(const std::string &key) const; + bool get_exists(std::string key) const; /*! * Checks to see if a given POST variable exists @@ -178,7 +178,7 @@ namespace fr * @param key The name of the POST variable * @return True if it does. False otherwise. */ - bool post_exists(const std::string &key) const; + bool post_exists(std::string key) const; /*! * Checks to see if a given header exists. @@ -186,7 +186,7 @@ namespace fr * @param key The name of the header * @return True if it does. False otherwise. */ - bool header_exists(const std::string &key) const; + bool header_exists(std::string key) const; /*! * Returns the requested URI diff --git a/src/Http.cpp b/src/Http.cpp index ce24504..e53a342 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -48,33 +48,39 @@ namespace fr body = body_; } - std::string &Http::get(const std::string &key) + std::string &Http::get(std::string key) { + std::transform(key.begin(), key.end(), key.begin(), ::tolower); return get_data[key]; } - std::string &Http::post(const std::string &key) + std::string &Http::post(std::string key) { + std::transform(key.begin(), key.end(), key.begin(), ::tolower); return post_data[key]; } - bool Http::get_exists(const std::string &key) const + bool Http::get_exists(std::string key) const { + std::transform(key.begin(), key.end(), key.begin(), ::tolower); return get_data.find(key) != get_data.end(); } - bool Http::post_exists(const std::string &key) const + bool Http::post_exists(std::string key) const { + std::transform(key.begin(), key.end(), key.begin(), ::tolower); return post_data.find(key) != post_data.end(); } - std::string &Http::header(const std::string &key) + std::string &Http::header(std::string key) { + std::transform(key.begin(), key.end(), key.begin(), ::tolower); return header_data[key]; } - bool Http::header_exists(const std::string &key) const + bool Http::header_exists(std::string key) const { + std::transform(key.begin(), key.end(), key.begin(), ::tolower); return header_data.find(key) != header_data.end(); } @@ -223,7 +229,7 @@ namespace fr } std::string header_name = str.substr(0, colon_pos); std::string header_value = str.substr(data_begin, data_len); - + std::transform(header_name.begin(), header_name.end(), header_name.begin(), ::tolower); header_data.emplace(std::move(header_name), std::move(header_value)); } diff --git a/tests/HttpRequestTest.cpp b/tests/HttpRequestTest.cpp index 3783019..12c22d3 100644 --- a/tests/HttpRequestTest.cpp +++ b/tests/HttpRequestTest.cpp @@ -139,7 +139,7 @@ TEST(HttpRequestTest, post_request_construction) //Create a request fr::HttpRequest request; request.header("MyHeader") = "header1"; - request.header("MyOtherHeader") = "header2"; + request.header("myotherheader") = "header2"; request.set_uri("/heyo/bobby"); request.get("var") = "20"; request.post("my_post") = "post_data"; @@ -150,7 +150,7 @@ TEST(HttpRequestTest, post_request_construction) //Parse it request = {}; request.parse(constructed_request.c_str(), constructed_request.size()); - ASSERT_EQ(request.header("MyHeader"), "header1"); + ASSERT_EQ(request.header("myheader"), "header1"); ASSERT_EQ(request.header("MyOtherHeader"), "header2"); ASSERT_EQ(request.get_uri(), "/heyo/bobby"); ASSERT_EQ(request.get("var"), "20");