CGI discussion and a little bit of work done

This commit is contained in:
LuckyLaszlo
2022-08-12 18:08:39 +02:00
parent cade79c37f
commit b44acafefe
9 changed files with 61 additions and 59 deletions

View File

@@ -104,7 +104,7 @@ print_client("headers");
_parse_port_hostname(this->get_rq_headers("Host")); // use getter for headers because it works case insensitive
// DEBUG
std::cerr << get_rq_method_str() << " " << get_rq_uri() << " " << get_rq_version() << "\n";
std::cerr << get_rq_method_str() << " " << get_rq_target() << " " << get_rq_version() << "\n";
// dont clear raw_request, we need it for future reparsing of body
// see call of parse_request() in _read_request()
@@ -202,10 +202,13 @@ void Client::parse_request_body()
status = 413; // HTTP Client Errors
}
bool Client::fill_script_path(std::string script)
// TODO HUGO : faire la fonction, mdr.
void Client::fill_script_path(const std::string &path, size_t pos)
{
size_t pos;
int len = script.size();
(void)path;
(void)pos;
/* size_t pos;
size_t len = path.size();
std::string path = this->get_rq_abs_path();
std::string tmp;
@@ -219,7 +222,7 @@ bool Client::fill_script_path(std::string script)
_request.script.info = path.substr(pos + len);
return true;
}
return false;
return false; */
}
void Client::clear()
@@ -240,7 +243,7 @@ void Client::clear_request()
{
clear_script();
_request.method = UNKNOWN;
_request.uri.clear();
_request.target.clear();
_request.version.clear();
_request.headers.clear();
_request.body.clear();
@@ -269,7 +272,7 @@ void Client::print_client(std::string message)
<< "get_cl_port() : [" << get_cl_port() << "]\n"
<< "get_cl_ip() : [" << get_cl_ip() << "]\n"
<< "get_rq_method_str() : [" << get_rq_method_str() << "]\n"
<< "get_rq_uri() : [" << get_rq_uri() << "]\n"
<< "get_rq_target() : [" << get_rq_target() << "]\n"
<< "get_rq_abs_path() : [" << get_rq_abs_path() << "]\n"
<< "get_rq_query() : [" << get_rq_query() << "]\n"
<< "get_rq_version() : [" << get_rq_version() << "]\n"
@@ -298,7 +301,7 @@ const listen_socket * Client::get_cl_lsocket() const { return _lsocket; }
http_method Client::get_rq_method() const { return _request.method; }
std::string Client::get_rq_method_str() const
{ return ::http_methods_to_str(_request.method); }
std::string Client::get_rq_uri() const { return _request.uri; }
std::string Client::get_rq_target() const { return _request.target; }
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; }
@@ -338,22 +341,22 @@ void Client::_parse_request_line()
else
{
_request.method = str_to_http_method(line[0]);
_request.uri = line[1];
_parse_request_uri(line[1]);
_request.target = line[1];
_parse_request_target(line[1]);
_request.version = line[2];
}
}
void Client::_parse_request_uri( std::string uri )
void Client::_parse_request_target( std::string target )
{
size_t pos;
pos = uri.find("?");
pos = target.find("?");
if (pos != std::string::npos)
_request.query = uri.substr(pos + 1);
_request.query = target.substr(pos + 1);
else
_request.query = "";
_request.abs_path = uri.substr(0, pos);
_request.abs_path = target.substr(0, pos);
}
void Client::_parse_request_fields()