http message parsin wip but really better
This commit is contained in:
@@ -77,22 +77,26 @@ Client & Client::operator=( Client const & rhs )
|
||||
// https://www.tutorialspoint.com/http/http_requests.htm
|
||||
void Client::parse_request(std::vector<ServerConfig> &servers)
|
||||
{
|
||||
std::map<std::string, std::string> headers;
|
||||
std::string body;
|
||||
// std::map<std::string, std::string> headers;
|
||||
// std::string body;
|
||||
std::string copy_request;
|
||||
|
||||
// DEBUG
|
||||
// std::cout << "\nREQUEST ____________\n" << raw_request << "\n_____________\n";
|
||||
clear_request(); // not mandatory
|
||||
|
||||
_parse_request_line();
|
||||
_parse_request_line(copy_request);
|
||||
if (status)
|
||||
return;
|
||||
_parse_request_headers(copy_request);
|
||||
if (status)
|
||||
return;
|
||||
_parse_request_headers();
|
||||
assigned_server = ::_determine_process_server(this, servers);
|
||||
assigned_location = ::_determine_location(*assigned_server, _request.abs_path);
|
||||
_check_request_errors();
|
||||
if (status)
|
||||
return;
|
||||
// use getter for headers because it works case insensitive
|
||||
_parse_port_hostname(this->get_rq_headers("Host"));
|
||||
|
||||
/* dont clear raw_request, we need it for future reparsing of body
|
||||
@@ -203,7 +207,7 @@ void Client::_parse_request_line()
|
||||
std::string raw_line;
|
||||
int ret;
|
||||
|
||||
raw_line = extract_line();
|
||||
raw_line = ::get_line(raw_request, 0, CRLF);
|
||||
line = ::split_trim(raw_line, " ", ' ');
|
||||
if (line.size() != 3)
|
||||
{
|
||||
@@ -233,8 +237,22 @@ void Client::_parse_request_uri( std::string uri )
|
||||
|
||||
void Client::_parse_request_headers()
|
||||
{
|
||||
// TODO: check error and adjust status
|
||||
_request.headers = ::parse_http_headers(raw_request);
|
||||
std::string headers;
|
||||
size_t pos;
|
||||
int ret;
|
||||
|
||||
headers = raw_request;
|
||||
// extract header part
|
||||
::extract_line(headers, 0, CRLF);
|
||||
pos = headers.find(CRLF);
|
||||
::extract_line(headers, pos); // delete from pos to the end
|
||||
// copy result of parser into headers
|
||||
ret = ::parse_http_headers(raw_request, _request.headers);
|
||||
if (ret > 0)
|
||||
{
|
||||
std::cerr << "err _parse_request_headers(): " << ret << " field are bad formated\n";
|
||||
status = 400; // "bad request"
|
||||
}
|
||||
}
|
||||
|
||||
void Client::_parse_port_hostname(std::string host)
|
||||
|
||||
Reference in New Issue
Block a user