diff --git a/srcs/Client.cpp b/srcs/Client.cpp index 3cdb737..c817f15 100644 --- a/srcs/Client.cpp +++ b/srcs/Client.cpp @@ -204,7 +204,7 @@ void Client::_parse_request_line() int ret; raw_line = extract_line(); - line = ::parse_http_first_line(raw_line); + line = ::split_trim(raw_line, " ", ' '); if (line.size() != 3) { std::cerr << "err _parse_first_line(): wrong number of elements (" << ret << " instead of 3)\n"; diff --git a/srcs/utils.cpp b/srcs/utils.cpp index 4b8c903..e0ca568 100644 --- a/srcs/utils.cpp +++ b/srcs/utils.cpp @@ -22,18 +22,19 @@ std::vector split(std::string input, char delimiter) } std::vector - 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 split_str; - std::string tmp; - size_t start = 0; - size_t end; + std::vector split_str; + std::string tmp; + int start = 0; + int end; end = input.find(delim); while (end != -1) { tmp = input.substr(start, end - start); - tmp = trim(tmp, ctrim); + if (ctrim != '\0') + tmp = trim(tmp, ctrim); if (tmp.size() != 0) split_str.push_back( tmp ); start = end + delim.size(); diff --git a/srcs/utils.hpp b/srcs/utils.hpp index 587b9f3..2d402fc 100644 --- a/srcs/utils.hpp +++ b/srcs/utils.hpp @@ -35,6 +35,7 @@ bool operator==(const listen_socket& lhs, int fd); bool operator==(int fd, const listen_socket& rhs); std::vector split(std::string input, char delimiter); +std::vector split_trim(std::string s, std::string d, char c); bool isNumeric(std::string str); bool isNumeric_btw(int low, int high, std::string str); std::string itos(int n); diff --git a/srcs/webserv/parsing_message_http.cpp b/srcs/webserv/parsing_message_http.cpp index 7430bba..9b8adc8 100644 --- a/srcs/webserv/parsing_message_http.cpp +++ b/srcs/webserv/parsing_message_http.cpp @@ -10,29 +10,6 @@ - parse_http_body(std::string message) */ -std::vector - parse_http_first_line(std::string line) -{ - std::vector sline; - std::vector 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 parse_http_headers(std::string message) { diff --git a/srcs/webserv/parsing_message_http.hpp b/srcs/webserv/parsing_message_http.hpp index a512aa1..5024d8d 100644 --- a/srcs/webserv/parsing_message_http.hpp +++ b/srcs/webserv/parsing_message_http.hpp @@ -8,9 +8,6 @@ # include # include "utils.hpp" -std::vector - parse_http_first_line(std::string message); - std::map parse_http_headers(std::string message);