Merge branch 'master' of bitbucket.org:LuckyLaszlo/webserv
This commit is contained in:
@@ -20,7 +20,7 @@ bool Webserv::_is_cgi(Client *client, std::string path)
|
||||
continue;
|
||||
if (file_type == IS_FILE)
|
||||
{
|
||||
file_mode = ::eval_file_mode( script_path, X_OK );
|
||||
file_mode = ::eval_file_access( script_path, X_OK );
|
||||
if (!file_mode)
|
||||
return true;
|
||||
}
|
||||
@@ -187,9 +187,13 @@ std::string Webserv::_exec_script(Client *client, char **env)
|
||||
void Webserv::_check_script_output(Client *client, std::string & output)
|
||||
{
|
||||
_check_script_status(client, output);
|
||||
///*DEBUG*/ std::cout << "\n" B_PURPLE "[script status]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
_check_script_fields(client, output);
|
||||
///*DEBUG*/ std::cout << "\n" B_PURPLE "[script fields]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
_remove_body_leading_empty_lines(output);
|
||||
///*DEBUG*/ std::cout << "\n" B_PURPLE "[script empty lines]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
_add_script_body_length_header(output);
|
||||
///*DEBUG*/ std::cout << "\n" B_PURPLE "[script content length]:" RESET "\n"; ::print_special(output); std::cout << B_PURPLE "-----------" RESET "\n\n";
|
||||
// _check_script_empty_lines(client, output);
|
||||
// _check_script_space_colons(client, output);
|
||||
// _check_script_new_lines(client, output);
|
||||
|
||||
@@ -12,7 +12,7 @@ void Webserv::_delete(Client *client, const std::string &path)
|
||||
void Webserv::_delete_file(Client *client, const std::string &path)
|
||||
{
|
||||
std::cout << "_delete_file()\n";
|
||||
client->status = ::eval_file_mode(path, W_OK);
|
||||
client->status = ::eval_file_access(path, W_OK);
|
||||
if (client->status)
|
||||
return;
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ void Webserv::_get_file(Client *client, const std::string &path)
|
||||
|
||||
std::cout << "_get_file()\n";
|
||||
|
||||
client->status = ::eval_file_mode(path, R_OK);
|
||||
client->status = ::eval_file_access(path, R_OK);
|
||||
if (client->status)
|
||||
return;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ void Webserv::_upload_files(Client *client)
|
||||
size_t pos;
|
||||
bool file_existed = false;
|
||||
|
||||
client->status = ::eval_file_mode(client->assigned_location->upload_dir, W_OK);
|
||||
client->status = ::eval_file_access(client->assigned_location->upload_dir, W_OK);
|
||||
if (client->status)
|
||||
return;
|
||||
|
||||
|
||||
@@ -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 << "\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";
|
||||
|
||||
std::cerr << "client->response.size() = " << client->response.size() << "\n"; // DEBUG
|
||||
ret = ::send(client->get_cl_fd(), client->response.c_str(), client->response.size(), 0);
|
||||
@@ -90,14 +90,11 @@ void Webserv::_construct_response(Client *client)
|
||||
if (_is_cgi(client, path))
|
||||
{
|
||||
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";
|
||||
_check_script_output(client, script_output);
|
||||
client->response += script_output;
|
||||
|
||||
/*DEBUG*/ std::cout << B_YELLOW "inside cgi" RESET "\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;
|
||||
@@ -134,14 +131,20 @@ void Webserv::_insert_status_line(Client *client)
|
||||
|
||||
void Webserv::_error_html_response(Client *client)
|
||||
{
|
||||
if (!client->assigned_server || client->assigned_server->error_pages[client->status].empty())
|
||||
std::cout << "_error_html_response()\n";
|
||||
|
||||
if (client->assigned_server
|
||||
&& !client->assigned_server->error_pages[client->status].empty()
|
||||
&& ::eval_file_access(client->assigned_server->error_pages[client->status], R_OK) == 0 )
|
||||
{
|
||||
_get_file(client, client->assigned_server->error_pages[client->status]);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string html_page = HTML_ERROR;
|
||||
::replace_all_substr(html_page, STATUS_PLACEHOLDER, _http_status[client->status]);
|
||||
_append_body(client, html_page, "html");
|
||||
}
|
||||
else
|
||||
_get_file(client, client->assigned_server->error_pages[client->status]);
|
||||
}
|
||||
|
||||
void Webserv::_append_body(Client *client, const std::string &body, const std::string &file_extension)
|
||||
|
||||
Reference in New Issue
Block a user