fixed _error_html_response()
+ renamed eval_file_mode() in eval_file_access() + memo update
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>404 Not Found</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">404 Not Found</h1>
|
||||
<hr>
|
||||
<p style="text-align:center">Le Webserv/0.1</p>
|
||||
</body>
|
||||
</html>
|
||||
27
memo.txt
27
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.
|
||||
@@ -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)
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<title>404 Not Found</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 style="text-align:center">Check it UP 404 Not Found</h1>
|
||||
<h1 style="text-align:center">Custom 404 Not Found</h1>
|
||||
<hr>
|
||||
<p style=\"text-align:center\">Le Webserv/0.1</p>
|
||||
<p style="text-align:center">(° ͜ʖ °) Grosse personnalisation</p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user