Skip to content

Commit

Permalink
replaced += by append and changed the order of strings to remove nece…
Browse files Browse the repository at this point in the history
…ssitity to substring at the the end.
  • Loading branch information
gittiver committed Jan 6, 2025
1 parent 6b33ffc commit 6565c10
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/crow/http_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace crow
else if (req_.upgrade)
{
// h2 or h2c headers
if (req_.get_header_value("upgrade").substr(0, 2) == "h2")
if (req_.get_header_value("upgrade").find("h2")==0)
{
// TODO(ipkn): HTTP/2
// currently, ignore upgrade header
Expand Down
2 changes: 1 addition & 1 deletion include/crow/http_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ namespace crow
#endif
if (file_info.statResult == 0 && S_ISREG(file_info.statbuf.st_mode))
{
std::size_t last_dot = path.find_last_of(".");
std::size_t last_dot = path.find_last_of('.');
std::string extension = path.substr(last_dot + 1);
code = 200;
this->add_header("Content-Length", std::to_string(file_info.statbuf.st_size));
Expand Down
14 changes: 10 additions & 4 deletions include/crow/query_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,11 @@ namespace crow
char* ret = get(name);
if (ret != nullptr)
{
const std::string key_name = name + '=';
for (unsigned int i = 0; i < key_value_pairs_.size(); i++)
{
std::string str_item(key_value_pairs_[i]);
if (str_item.substr(0, name.size() + 1) == name + '=')
if (str_item.find(key_name)==0)
{
key_value_pairs_.erase(key_value_pairs_.begin() + i);
break;
Expand Down Expand Up @@ -416,14 +417,18 @@ namespace crow
std::vector<char*> pop_list(const std::string& name, bool use_brackets = true)
{
std::vector<char*> ret = get_list(name, use_brackets);
const size_t name_len = name.length();
if (!ret.empty())
{
for (unsigned int i = 0; i < key_value_pairs_.size(); i++)
{
std::string str_item(key_value_pairs_[i]);
if ((use_brackets ? (str_item.substr(0, name.size() + 3) == name + "[]=") : (str_item.substr(0, name.size() + 1) == name + '=')))
{
if (str_item.find(name)==0) {
if (use_brackets && str_item.find("[]=",name_len)==name_len) {
key_value_pairs_.erase(key_value_pairs_.begin() + i--);
} else if (!use_brackets && str_item.find('=',name_len)==name_len ) {
key_value_pairs_.erase(key_value_pairs_.begin() + i--);
}
}
}
}
Expand Down Expand Up @@ -454,13 +459,14 @@ namespace crow
/// Works the same as \ref get_dict() but removes the values from the query string.
std::unordered_map<std::string, std::string> pop_dict(const std::string& name)
{
const std::string name_value = name +'[';
std::unordered_map<std::string, std::string> ret = get_dict(name);
if (!ret.empty())
{
for (unsigned int i = 0; i < key_value_pairs_.size(); i++)
{
std::string str_item(key_value_pairs_[i]);
if (str_item.substr(0, name.size() + 1) == name + '[')
if (str_item.find(name_value)==0)
{
key_value_pairs_.erase(key_value_pairs_.begin() + i--);
}
Expand Down

0 comments on commit 6565c10

Please sign in to comment.