script path is found and fill

This commit is contained in:
hugogogo
2022-08-07 15:51:36 +02:00
parent e0fd743b5b
commit 7ecfc22c7b
5 changed files with 106 additions and 46 deletions

View File

@@ -77,8 +77,11 @@ void Client::parse_request()
// DEBUG
std::cout << "\n"
<< "request:\n" << raw_request
<< "START _______________________\n\n"
<< "START _______________________\n\n"
<< raw_request
<< "\nSCRIPT PATH _________________\n"
<< "\npath:" << _request.script.path
<< "\npath_info:" << _request.script.info
<< "\n END _______________________\n";
pos = (raw_request).find(CRLF CRLF);
@@ -92,6 +95,24 @@ std::cout << "\n"
// add "raw_request.clear()" after parsing ? for little less memory usage ?
}
bool Client::fill_script_path(std::string script)
{
size_t pos;
int len = script.size();
std::string path = this->get_rq_abs_path();
std::string tmp;
pos = path.find(script);
if (pos != std::string::npos)
{
tmp = path.substr(0, pos + len);
_request.script.path = "./srcs/cgi-bin" + tmp; // TODO: deal with cgi path
_request.script.info = path.substr(pos + len);
return true;
}
return false;
}
void Client::clear()
{
clear_request();
@@ -103,6 +124,7 @@ void Client::clear()
void Client::clear_request()
{
clear_script();
_request.method = UNKNOWN;
_request.uri.clear();
_request.version.clear();
@@ -114,6 +136,12 @@ void Client::clear_request()
_request.hostname.clear();
}
void Client::clear_script()
{
_request.script.path.clear();
_request.script.info.clear();
}
/*********************************************
* GETTERS
@@ -136,8 +164,17 @@ 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_script_path()const { return _request.script.path; }
std::string Client::get_rq_script_info()const { return _request.script.info; }
std::string Client::get_rq_headers(const std::string & key) const
{ return _request.headers.find(::str_tolower(key))->second; }
{
std::map<std::string, std::string>::const_iterator it;
it = _request.headers.find(::str_tolower(key));
if (it == _request.headers.end())
return "";
return it->second;
}
/*********************************************
@@ -159,9 +196,7 @@ void Client::_parse_request_line( std::string rline )
tmp = ::trim(sline[0], ' ');
tmp = ::trim(tmp, '\r');
_request.method = str_to_http_method(tmp);
// TODO uri in request_line
// https://www.rfc-editor.org/rfc/rfc7230#section-5.3
// https://stackoverflow.com/questions/40311306/when-is-absoluteuri-used-from-the-http-request-specs
// uri
tmp = ::trim(sline[1], ' ');
tmp = ::trim(tmp, '\r');
_request.uri = tmp;