Merge branch 'hugo2'

+ changed the appropriate getters for client
+ moved the functions to parse the http message
  (first line, headers, and body)
  outside client, in parsing_http_message.cpp
+ resolved some of the throw problems
This commit is contained in:
hugogogo
2022-08-09 15:54:40 +02:00
24 changed files with 205391 additions and 214 deletions

View File

@@ -23,8 +23,19 @@ std::vector<std::string> split(std::string input, char delimiter)
std::string trim(std::string str, char c)
{
str = str.substr(str.find_first_not_of(c));
str = str.substr(0, str.find_last_not_of(c) + 1);
size_t pos;
// delete leadings c
pos = str.find_first_not_of(c);
if (pos == std::string::npos)
return str;
str = str.substr(pos);
// delete endings c
pos = str.find_last_not_of(c);
if (pos == std::string::npos)
return str;
str = str.substr(0, pos + 1);
return str;
}
@@ -137,8 +148,37 @@ void replace_all_substr(std::string &str, const std::string &ori_substr, const s
}
}
std::string str_tolower(std::string str)
{
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return str;
}
void del_line_in_str(std::string * str, size_t pos, std::string delim)
{
size_t begin;
size_t end;
begin = (*str).rfind(delim, pos);
if (begin == std::string::npos)
begin = 0;
else
begin += delim.size();
end = (*str).find(delim, pos);
if (end == std::string::npos)
end = 0;
else
end += delim.size();
(*str).erase(begin, end - begin);
}
bool operator==(const listen_socket& lhs, int fd)
{ return lhs.fd == fd; }
bool operator==(int fd, const listen_socket& rhs)
{ return fd == rhs.fd; }