key fields headers in map are in lowercase
+ getters for this map are case insensitive + change request fiel 'path' for 'uri', 'query', and 'abs_path'
This commit is contained in:
@@ -74,6 +74,7 @@ void Client::parse_request()
|
||||
std::vector<std::string> list;
|
||||
size_t pos;
|
||||
|
||||
// DEBUG
|
||||
std::cout << "\n"
|
||||
<< "request:\n" << raw_request
|
||||
<< "START _______________________\n\n"
|
||||
@@ -87,7 +88,7 @@ std::cout << "\n"
|
||||
list.erase(list.begin());
|
||||
_parse_request_headers(list);
|
||||
_parse_request_body(pos + 4);
|
||||
_parse_port_hostname(_request.headers["Host"]);
|
||||
_parse_port_hostname(this->get_rq_headers("Host"));
|
||||
// add "raw_request.clear()" after parsing ? for little less memory usage ?
|
||||
}
|
||||
|
||||
@@ -103,10 +104,14 @@ void Client::clear()
|
||||
void Client::clear_request()
|
||||
{
|
||||
_request.method = UNKNOWN;
|
||||
_request.path.clear();
|
||||
_request.uri.clear();
|
||||
_request.version.clear();
|
||||
_request.headers.clear();
|
||||
_request.body.clear();
|
||||
_request.abs_path.clear();
|
||||
_request.query.clear();
|
||||
_request.port.clear();
|
||||
_request.hostname.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -115,25 +120,24 @@ void Client::clear_request()
|
||||
*********************************************/
|
||||
|
||||
// client side
|
||||
int Client::get_cl_fd() const { return _fd; }
|
||||
int Client::get_cl_fd() const { return _fd; }
|
||||
std::string Client::get_cl_ip() const { return _ip; }
|
||||
listen_socket * Client::get_cl_lsocket() const { return _lsocket; }
|
||||
std::string Client::get_cl_port() const { return _port; }
|
||||
|
||||
// requette
|
||||
http_method Client::get_rq_method()const { return _request.method; }
|
||||
http_method Client::get_rq_method() const { return _request.method; }
|
||||
std::string Client::get_rq_method_str() const
|
||||
{
|
||||
std::string method;
|
||||
method = ::http_methods_to_str(_request.method);
|
||||
return method;
|
||||
}
|
||||
std::string Client::get_rq_path() const { return _request.path; }
|
||||
{ return ::http_methods_to_str(_request.method); }
|
||||
std::string Client::get_rq_uri() const { return _request.uri; }
|
||||
std::string Client::get_rq_abs_path() const { return _request.abs_path; }
|
||||
std::string Client::get_rq_query() const { return _request.query; }
|
||||
std::string Client::get_rq_version() const { return _request.version; }
|
||||
std::string Client::get_rq_body() const { return _request.body; }
|
||||
std::string Client::get_rq_port() const { return _request.port; }
|
||||
std::string Client::get_rq_hostname() const { return _request.hostname; }
|
||||
std::string Client::get_rq_headers(const std::string & key)
|
||||
{ return _request.headers[key]; }
|
||||
std::string Client::get_rq_headers(const std::string & key) const
|
||||
{ return _request.headers.find(::str_tolower(key))->second; }
|
||||
|
||||
|
||||
/*********************************************
|
||||
@@ -160,13 +164,26 @@ void Client::_parse_request_line( std::string rline )
|
||||
// https://stackoverflow.com/questions/40311306/when-is-absoluteuri-used-from-the-http-request-specs
|
||||
tmp = ::trim(sline[1], ' ');
|
||||
tmp = ::trim(tmp, '\r');
|
||||
_request.path = tmp;
|
||||
_request.uri = tmp;
|
||||
_parse_request_uri( tmp );
|
||||
// http version
|
||||
tmp = ::trim(sline[2], ' ');
|
||||
tmp = ::trim(tmp, '\r');
|
||||
_request.version = tmp;
|
||||
}
|
||||
|
||||
void Client::_parse_request_uri( std::string uri )
|
||||
{
|
||||
size_t pos;
|
||||
|
||||
pos = uri.find("?");
|
||||
if (pos != std::string::npos)
|
||||
_request.query = uri.substr(pos + 1);
|
||||
else
|
||||
_request.query = "";
|
||||
_request.abs_path = uri.substr(0, pos);
|
||||
}
|
||||
|
||||
void Client::_parse_request_headers( std::vector<std::string> list )
|
||||
{
|
||||
std::string key;
|
||||
@@ -180,6 +197,7 @@ void Client::_parse_request_headers( std::vector<std::string> list )
|
||||
key = (*it).substr( 0, pos );
|
||||
key = ::trim(key, ' ');
|
||||
key = ::trim(key, '\r');
|
||||
key = ::str_tolower(key);
|
||||
val = (*it).substr( pos + 1 );
|
||||
val = ::trim(val, ' ');
|
||||
val = ::trim(val, '\r');
|
||||
|
||||
Reference in New Issue
Block a user