fixed _error_html_response()
+ renamed eval_file_mode() in eval_file_access() + memo update
This commit is contained in:
@@ -153,10 +153,9 @@ std::string http_methods_to_str(unsigned int methods)
|
||||
|
||||
file_type eval_file_type(const std::string &path)
|
||||
{
|
||||
const char *tmp_path = path.c_str(); // variable superflu ?
|
||||
struct stat s;
|
||||
|
||||
if (stat(tmp_path, &s) != -1)
|
||||
if (stat(path.c_str(), &s) != -1)
|
||||
{
|
||||
if (S_ISREG(s.st_mode))
|
||||
return (IS_FILE);
|
||||
@@ -171,8 +170,7 @@ file_type eval_file_type(const std::string &path)
|
||||
return (IS_OTHER);
|
||||
}
|
||||
|
||||
// rename in "eval_file_access" ?
|
||||
size_t eval_file_mode(const std::string &path, int mode)
|
||||
size_t eval_file_access(const std::string &path, int mode)
|
||||
{
|
||||
if (::access(path.c_str(), F_OK) == -1)
|
||||
{
|
||||
|
||||
@@ -67,7 +67,7 @@ std::string trim(std::string str, char del);
|
||||
http_method str_to_http_method(std::string &str);
|
||||
std::string http_methods_to_str(unsigned int methods);
|
||||
file_type eval_file_type(const std::string &path);
|
||||
size_t eval_file_mode(const std::string &path, int mode);
|
||||
size_t eval_file_access(const std::string &path, int mode);
|
||||
void replace_all_substr(std::string &str, const std::string &ori_substr, const std::string &new_substr);
|
||||
std::string str_tolower(std::string str);
|
||||
std::string extract_line(std::string & str, size_t pos = 0, std::string delim = "\n");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -131,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