From b9d4317f513bdef5d552eab6c8ebf2f49e629ed6 Mon Sep 17 00:00:00 2001 From: Hugo LAMY Date: Mon, 15 Aug 2022 01:52:36 +0200 Subject: [PATCH] in _is_cgi, fix error in return http error status + fix error in checking script output : reverse order between calcul of content_length and erasing empty line --- default.config | 10 +++++----- srcs/webserv/cgi_script.cpp | 5 ++--- srcs/webserv/response.cpp | 9 +++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/default.config b/default.config index 125be8b..721ac51 100644 --- a/default.config +++ b/default.config @@ -31,11 +31,11 @@ server { upload_dir ./www/uploaded/; } -# location /srcs/cgi-bin/ { -# root ./srcs/cgi-bin/; -# allow_methods POST; -# cgi_ext php; -# } + location /srcs/cgi-bin/ { + root ./srcs/cgi-bin/; + allow_methods POST; + cgi_ext php; + } location /list { autoindex on; diff --git a/srcs/webserv/cgi_script.cpp b/srcs/webserv/cgi_script.cpp index 7978ddb..7385301 100644 --- a/srcs/webserv/cgi_script.cpp +++ b/srcs/webserv/cgi_script.cpp @@ -5,7 +5,7 @@ bool Webserv::_is_cgi(Client *client, std::string path) { std::string script_path; size_t file_type; - size_t file_mode; + size_t file_mode = client->status; size_t pos = 0; while (pos != NPOS) @@ -160,7 +160,6 @@ std::string Webserv::_exec_script(Client *client, char **env) // for tests execve crash : //execve("wrong", nll, env); std::cerr << "execve crashed.\n"; - // TODO HUGO : check errno } else //parent @@ -189,8 +188,8 @@ void Webserv::_check_script_output(Client *client, std::string & output) { _check_script_status(client, output); _check_script_fields(client, output); - _add_script_body_length_header(output); _remove_body_leading_empty_lines(output); + _add_script_body_length_header(output); // _check_script_empty_lines(client, output); // _check_script_space_colons(client, output); // _check_script_new_lines(client, output); diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 20f9e41..556ab4d 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -47,7 +47,7 @@ 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 << 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"; std::cerr << "client->response.size() = " << client->response.size() << "\n"; // DEBUG ret = ::send(client->get_cl_fd(), client->response.c_str(), client->response.size(), 0); @@ -86,13 +86,14 @@ void Webserv::_construct_response(Client *client) { script_output = _exec_cgi(client); -/*DEBUG*/ std::cout << "\n" B_PURPLE "[script output]:" RESET "\n"; ::print_special(script_output); std::cout << B_PURPLE "-----------" RESET "\n\n"; -/*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"; +///*DEBUG*/ std::cout << "\n" B_PURPLE "[response]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; _check_script_output(client, script_output); 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"; +/*DEBUG*/ std::cout << B_YELLOW "inside cgi" RESET "\n"; +///*DEBUG*/ std::cout << "\n" B_PURPLE "[response + output]:" RESET "\n"; ::print_special(client->response); std::cout << B_PURPLE "-----------" RESET "\n\n"; return; }