Debug in progress, somes fix but not the main problem

This commit is contained in:
lperrey
2022-08-18 06:03:09 +02:00
parent a008c12058
commit 3d17db996a
13 changed files with 136 additions and 117 deletions

View File

@@ -25,6 +25,7 @@ void Webserv::_response(Client *client)
|| client->status == 400 // TODO: Refactoring
|| client->status == 408
|| client->status == 413)
// || client->cgi_state == CGI_OUTPUT_COMPLETE) // DEBUG
_close_client(client->get_cl_fd());
else
{
@@ -48,8 +49,8 @@ int Webserv::_send_response(Client *client)
if (!client->status)
{
_construct_response(client);
if (client->cgi_state == CGI_WAIT_FOR_OUTPUT
|| client->cgi_state == CGI_WAIT_TO_EXEC)
if (client->cgi_state == CGI_WAIT_TO_EXEC
|| client->cgi_state == CGI_OUTPUT_READING)
return SEND_IN_PROGRESS;
}
@@ -72,6 +73,11 @@ int Webserv::_send_response(Client *client)
std::cerr << "SEND RET 0 for client.fd =" << client->get_cl_fd() << "\n"; // DEBUG
return SEND_CLOSE;
}
if (ret < (int)client->response.size())
{
std::cerr << "send() as not send all data, IT CAN HAPPEN !" << "\n"; // DEBUG
throw ExecFail(); // DEBUG, TODO, A ENLEVER ABSOLEMENT, WHILE TEMP =D
}
// /* Debug */ std::cerr << "ret send() = " << ret << "\n"; // DEBUG
return SEND_COMPLETE;
@@ -99,16 +105,26 @@ void Webserv::_construct_response(Client *client)
if (client->cgi_state == CGI_READY_TO_EXEC)
{
std::string body = client->get_rq_body();
::write(client->cgi_pipe_w_to_child, body.c_str(), body.size());
std::cerr << "client.fd for write body =" << client->get_cl_fd() << "\n"; // DEBUG
std::cerr << "client.cgi_pipe_w_to_child for write body =" << client->cgi_pipe_w_to_child << "\n"; // DEBUG
if (::write(client->cgi_pipe_w_to_child, body.c_str(), body.size()) == -1)
{
std::perror("err write()");
_close_client_cgi_pipes(client);
client->status = 500;
client->cgi_state = CGI_NO_CGI;
return;
}
_exec_cgi(client);
}
else if (client->cgi_state == CGI_OUTPUT_READY)
else if (client->cgi_state == CGI_OUTPUT_COMPLETE)
{
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[response]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[script output]:" RESET "\n"; ::print_special(client->cgi_output); std::cout << B_PURPLE "-----------" RESET "\n\n";
_check_script_output(client, client->cgi_output); // FD_CGI : adjust for client->cgi_output;
if (client->status < 400)
if (client->status < 400 || client->status >= 600)
client->response += client->cgi_output;
// client->cgi_state = CGI_NO_CGI; // Not indispensable, reset when client.clear()
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
}
else if (_is_cgi(client, path))