clean comment and stuff

This commit is contained in:
lperrey
2022-08-18 12:44:09 +02:00
parent 9b0fcc1520
commit 469eca8aa9
27 changed files with 100 additions and 325 deletions

View File

@@ -22,10 +22,9 @@ void Webserv::_response(Client *client)
else if (ret == SEND_COMPLETE)
{
if (client->get_rq_headers("Connection") == "close"
|| client->status == 400 // TODO: Refactoring
|| client->status == 400
|| client->status == 408
|| client->status == 413)
// || client->cgi_state == CGI_OUTPUT_COMPLETE) // DEBUG
_close_client(client->get_cl_fd());
else
{
@@ -42,9 +41,7 @@ int Webserv::_send_response(Client *client)
std::cerr << "send()\n";
if (client->response.empty())
{
_append_base_headers(client);
}
if (!client->status)
{
@@ -58,34 +55,27 @@ int Webserv::_send_response(Client *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::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)
{
std::perror("err send()");
std::cerr << "client.fd =" << client->get_cl_fd() << "\n"; // DEBUG
return SEND_CLOSE;
}
if (ret == 0) // actually never happen ?
if (ret == 0)
{
std::cerr << "SEND RET 0 for client.fd =" << client->get_cl_fd() << "\n"; // DEBUG
std::cerr << "send() ret == 0 never happens ?" << "\n"; // Debug
return SEND_CLOSE;
}
// /* Debug */ std::cerr << "ret send() = " << ret << "\n"; // DEBUG
return SEND_COMPLETE;
}
void Webserv::_append_base_headers(Client *client)
{
std::cerr << "_append_base_headers()\n"; // debug
client->response.append("Server: Webserv/0.1" CRLF);
if (client->get_rq_headers("Connection") == "close"
|| client->status == 400 // TODO: Refactoring
|| client->status == 400
|| client->status == 408
|| client->status == 413)
client->response.append("Connection: close" CRLF);
@@ -97,7 +87,7 @@ void Webserv::_construct_response(Client *client)
{
std::string path;
std::string script_output;
path = _replace_url_root(client, client->get_rq_abs_path());
if (client->cgi_state == CGI_READY_TO_EXEC)
{
@@ -108,13 +98,9 @@ void Webserv::_construct_response(Client *client)
}
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;
_check_script_output(client, client->cgi_output);
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))
_cgi_open_pipes(client);
@@ -124,9 +110,6 @@ 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 << "Path again: " << path << '\n'; // debug
switch (client->get_rq_method())
{
case (GET):
@@ -142,13 +125,10 @@ void Webserv::_process_method(Client *client, std::string &path)
std::string Webserv::_replace_url_root(Client *client, std::string path)
{
// /* 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);
// /* Debug */ std::cerr << "path after = " << path << "\n"; // DEBUG
return path;
}
@@ -212,4 +192,3 @@ void Webserv::_append_body(Client *client, const std::string &body, const std::s
client->response.append(CRLF);
client->response.append(body);
}