wip parsing first line http message with new utils functions

This commit is contained in:
hugogogo
2022-08-10 20:27:48 +02:00
parent 9a379c835d
commit 11f71ea74f
5 changed files with 9 additions and 33 deletions

View File

@@ -204,7 +204,7 @@ void Client::_parse_request_line()
int ret; int ret;
raw_line = extract_line(); raw_line = extract_line();
line = ::parse_http_first_line(raw_line); line = ::split_trim(raw_line, " ", ' ');
if (line.size() != 3) if (line.size() != 3)
{ {
std::cerr << "err _parse_first_line(): wrong number of elements (" << ret << " instead of 3)\n"; std::cerr << "err _parse_first_line(): wrong number of elements (" << ret << " instead of 3)\n";

View File

@@ -22,17 +22,18 @@ std::vector<std::string> split(std::string input, char delimiter)
} }
std::vector<std::string> std::vector<std::string>
split_trim(std::string input, std::string delim = "\n", char ctrim = '') split_trim(std::string input, std::string delim = "\n", char ctrim = '\0')
{ {
std::vector<std::string> split_str; std::vector<std::string> split_str;
std::string tmp; std::string tmp;
size_t start = 0; int start = 0;
size_t end; int end;
end = input.find(delim); end = input.find(delim);
while (end != -1) while (end != -1)
{ {
tmp = input.substr(start, end - start); tmp = input.substr(start, end - start);
if (ctrim != '\0')
tmp = trim(tmp, ctrim); tmp = trim(tmp, ctrim);
if (tmp.size() != 0) if (tmp.size() != 0)
split_str.push_back( tmp ); split_str.push_back( tmp );

View File

@@ -35,6 +35,7 @@ bool operator==(const listen_socket& lhs, int fd);
bool operator==(int fd, const listen_socket& rhs); bool operator==(int fd, const listen_socket& rhs);
std::vector<std::string> split(std::string input, char delimiter); std::vector<std::string> split(std::string input, char delimiter);
std::vector<std::string> split_trim(std::string s, std::string d, char c);
bool isNumeric(std::string str); bool isNumeric(std::string str);
bool isNumeric_btw(int low, int high, std::string str); bool isNumeric_btw(int low, int high, std::string str);
std::string itos(int n); std::string itos(int n);

View File

@@ -10,29 +10,6 @@
- parse_http_body(std::string message) - parse_http_body(std::string message)
*/ */
std::vector<std::string>
parse_http_first_line(std::string line)
{
std::vector<std::string> sline;
std::vector<std::string> line = "";
std::string sub;
std::string tmp;
size_t pos;
sline = ::split(line, ' ');
if (sline.size() == 3)
{
for (int i = 0; i < 3; i++)
{
tmp = sline[i];
tmp = ::trim(tmp, '\r');
tmp = ::trim(tmp, ' ');
line.push_back(tmp);
}
}
return line;
}
std::map<std::string, std::string> std::map<std::string, std::string>
parse_http_headers(std::string message) parse_http_headers(std::string message)
{ {

View File

@@ -8,9 +8,6 @@
# include <map> # include <map>
# include "utils.hpp" # include "utils.hpp"
std::vector<std::string>
parse_http_first_line(std::string message);
std::map<std::string, std::string> std::map<std::string, std::string>
parse_http_headers(std::string message); parse_http_headers(std::string message);