body write to CGI now monitored by epoll

+ kermit.jpg :)
This commit is contained in:
lperrey
2022-08-17 23:42:12 +02:00
parent 2613ca2e1a
commit b34e49311b
13 changed files with 302 additions and 193 deletions

View File

@@ -43,28 +43,21 @@ int Webserv::_send_response(Client *client)
if (client->response.empty())
{
_append_base_headers(client);
if (!client->status)
{
_construct_response(client);
if (client->cgi_pipe_rfd)
return SEND_IN_PROGRESS;
}
}
else if (!client->cgi_output.empty())
if (!client->status)
{
/*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)
client->response += client->cgi_output;
/*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
_construct_response(client);
if (client->cgi_state == CGI_WAIT_FOR_OUTPUT
|| client->cgi_state == CGI_WAIT_TO_EXEC)
return SEND_IN_PROGRESS;
}
_insert_status_line(client);
if (client->status >= 400)
_error_html_response(client);
/*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output + headers]:" RESET "\n"; ::print_special(client->response); std::cout << "\n" B_PURPLE "-----------" RESET "\n\n";
// /*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output + headers]:" RESET "\n"; ::print_special(client->response); std::cout << "\n" B_PURPLE "-----------" RESET "\n\n";
// /* Debug */ std::cerr << "client->response.size() = " << client->response.size() << "\n"; // DEBUG
ret = ::send(client->get_cl_fd(), client->response.c_str(), client->response.size(), 0);
@@ -103,12 +96,25 @@ void Webserv::_construct_response(Client *client)
std::string script_output;
path = _replace_url_root(client, client->get_rq_abs_path());
if (_is_cgi(client, path))
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());
_exec_cgi(client);
return;
}
_process_method(client, path);
else if (client->cgi_state == CGI_OUTPUT_READY)
{
// /*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)
client->response += client->cgi_output;
// /*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))
_cgi_open_pipes(client);
else
_process_method(client, path);
}
void Webserv::_process_method(Client *client, std::string &path)