diff --git a/default_error_pages/404.html b/default_error_pages/404.html deleted file mode 100644 index df4d27c..0000000 --- a/default_error_pages/404.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - 404 Not Found - - -

404 Not Found

-
-

Le Webserv/0.1

- - \ No newline at end of file diff --git a/memo.txt b/memo.txt index 7ded14e..6987b8b 100644 --- a/memo.txt +++ b/memo.txt @@ -1,19 +1,22 @@ -IN 42 SUBJECT AND/OR PRIORITY : +----Priorité élevée------------------------ - CGI (TODO HUGO) - Need to test normal body parsing (Verif avec HUGO) -- Ecrire des tests ! -- handle redirection (Work, but weird behavior need deeper test) - - curl --resolve, for testing hostname curl -v --resolve server1:4040:127.0.0.1 --resolve server2:4040:127.0.0.1 server1:4040 - test limit de connexions sur listen() ------------------------------ -Si ce n'est pas deja fait : -peut-être check si ip > 32bits ------------------------------ +- handle redirection (Work, but weird behavior need deeper test) +- Ecrire des tests ! + +----Priorité modérée------------------------ +- namespace utils ? +- change "std::string" to reference "std::string &" in most functions +and add "const" if apropriate. +- peut-être check si ip > 32bits + +----Priorité faible------------------------ - chunked request (need testing) - client_body_limit 0 valeur special pour desactiver dans config - gerer le champ "Accept" du client @@ -26,11 +29,3 @@ peut-être check si ip > 32bits - change "std::string" to reference "std::string &" in most functions and add "const" if apropriate. - Il faut vérifier le path de la requête, voir si le serveur est bien censé délivrer cette ressource et si le client y a accès, avant d'appeler le CGI. - - -__________________________ --------------------------- - -----Discord 42------------ -Un truc cool et surtout bien utile ici c'est d'utiliser un proxy entre ton navigateur et ton serveur pour vérifier ce qui est envoyé en raw. Les navigateurs peuvent avoir des comportements différents. -Vous avez des modules sur vos navigateur ou des logiciels externe. C'est assez rapide et gratuit. \ No newline at end of file diff --git a/srcs/utils.cpp b/srcs/utils.cpp index d85d5d5..4c82845 100644 --- a/srcs/utils.cpp +++ b/srcs/utils.cpp @@ -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) { diff --git a/srcs/utils.hpp b/srcs/utils.hpp index 44f5347..7d00e1b 100644 --- a/srcs/utils.hpp +++ b/srcs/utils.hpp @@ -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"); diff --git a/srcs/webserv/cgi_script.cpp b/srcs/webserv/cgi_script.cpp index 8949a77..815218e 100644 --- a/srcs/webserv/cgi_script.cpp +++ b/srcs/webserv/cgi_script.cpp @@ -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; } diff --git a/srcs/webserv/method_delete.cpp b/srcs/webserv/method_delete.cpp index 16c7d94..248471e 100644 --- a/srcs/webserv/method_delete.cpp +++ b/srcs/webserv/method_delete.cpp @@ -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; diff --git a/srcs/webserv/method_get.cpp b/srcs/webserv/method_get.cpp index 4649dd2..e84a7bb 100644 --- a/srcs/webserv/method_get.cpp +++ b/srcs/webserv/method_get.cpp @@ -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; diff --git a/srcs/webserv/method_post.cpp b/srcs/webserv/method_post.cpp index ce7309b..8611770 100644 --- a/srcs/webserv/method_post.cpp +++ b/srcs/webserv/method_post.cpp @@ -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; diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 6d2bcc6..627a868 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 << "\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) diff --git a/www/error_pages/error_404.html b/www/error_pages/error_404.html index fa18a2b..114a656 100644 --- a/www/error_pages/error_404.html +++ b/www/error_pages/error_404.html @@ -4,8 +4,8 @@ 404 Not Found -

Check it UP 404 Not Found

+

Custom 404 Not Found


-

Le Webserv/0.1

+

(° ͜ʖ °) Grosse personnalisation