wip parsing first line http message with new utils functions
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -22,18 +22,19 @@ std::vector<std::string> split(std::string input, char delimiter)
|
||||
}
|
||||
|
||||
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::string tmp;
|
||||
size_t start = 0;
|
||||
size_t end;
|
||||
std::vector<std::string> 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();
|
||||
|
||||
@@ -35,6 +35,7 @@ bool operator==(const listen_socket& lhs, int fd);
|
||||
bool operator==(int fd, const listen_socket& rhs);
|
||||
|
||||
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_btw(int low, int high, std::string str);
|
||||
std::string itos(int n);
|
||||
|
||||
@@ -10,29 +10,6 @@
|
||||
- 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>
|
||||
parse_http_headers(std::string message)
|
||||
{
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
# include <map>
|
||||
# include "utils.hpp"
|
||||
|
||||
std::vector<std::string>
|
||||
parse_http_first_line(std::string message);
|
||||
|
||||
std::map<std::string, std::string>
|
||||
parse_http_headers(std::string message);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user