merging small fixes andmore telnet tests

This commit is contained in:
Me
2022-08-17 02:51:32 +02:00
9 changed files with 278 additions and 116 deletions

View File

@@ -3,7 +3,7 @@
enum send_return
{
SEND_IN_PROGRESS, // unused
SEND_IN_PROGRESS,
SEND_COMPLETE,
SEND_CLOSE,
};
@@ -40,16 +40,33 @@ int Webserv::_send_response(Client *client)
std::cerr << "send()\n";
_append_base_headers(client);
if (!client->status)
_construct_response(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())
{
// /*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(script_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";
}
_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";
std::cerr << "client->response.size() = " << client->response.size() << "\n"; // DEBUG
// /* 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);
if (ret == -1)
{
@@ -62,7 +79,7 @@ int Webserv::_send_response(Client *client)
std::cerr << "SEND RET 0 for client.fd =" << client->get_cl_fd() << "\n"; // DEBUG
return SEND_CLOSE;
}
std::cerr << "ret send() = " << ret << "\n"; // DEBUG
// /* Debug */ std::cerr << "ret send() = " << ret << "\n"; // DEBUG
return SEND_COMPLETE;
}
@@ -89,14 +106,7 @@ void Webserv::_construct_response(Client *client)
path = _replace_url_root(client, client->get_rq_abs_path());
if (_is_cgi(client, path))
{
script_output = _exec_cgi(client);
//*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(script_output); std::cout << B_PURPLE "-----------" RESET "\n\n";
_check_script_output(client, script_output);
if (client->status < 400)
client->response += script_output;
//*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n";
_exec_cgi(client);
return;
}
_process_method(client, path);
@@ -104,7 +114,7 @@ void Webserv::_construct_response(Client *client)
void Webserv::_process_method(Client *client, std::string &path)
{
std::cerr << "allow_methods = " << http_methods_to_str(client->assigned_location->allow_methods) << "\n"; // debug
// std::cerr << "allow_methods = " << http_methods_to_str(client->assigned_location->allow_methods) << "\n"; // debug
std::cerr << "Path again: " << path << '\n'; // debug
switch (client->get_rq_method())
@@ -122,13 +132,13 @@ void Webserv::_process_method(Client *client, std::string &path)
std::string Webserv::_replace_url_root(Client *client, std::string path)
{
std::cerr << "assigned_location->path = " << client->assigned_location->path << "\n"; // debug
std::cerr << "path before = " << path << "\n"; // DEBUG
// /* Debug */ std::cerr << "assigned_location->path = " << client->assigned_location->path << "\n"; // debug
// /* Debug */ std::cerr << "path before = " << path << "\n"; // DEBUG
if (client->assigned_location->path == "/")
path.insert(0, client->assigned_location->root);
else
path.replace(0, client->assigned_location->path.size(), client->assigned_location->root);
std::cerr << "path after = " << path << "\n"; // DEBUG
// /* Debug */ std::cerr << "path after = " << path << "\n"; // DEBUG
return path;
}