DELETE method tested and fixed

+ added 404 for directories without index and autoindex
+ minors adjustements
This commit is contained in:
LuckyLaszlo
2022-08-15 18:16:11 +02:00
parent a284e400c1
commit 3fe37ea451
7 changed files with 62 additions and 64 deletions

View File

@@ -16,9 +16,10 @@ std::string Webserv::_replace_url_root(Client *client, std::string path)
// const?
void Webserv::_get(Client *client, std::string &path)
{
// Index/Autoindex block
/*
https://www.rfc-editor.org/rfc/rfc9110.html#name-get
*/
std::cout << "_get()\n";
if (eval_file_type(path) == IS_DIR)
{
if (path[path.size() - 1] != '/')
@@ -34,12 +35,14 @@ void Webserv::_get(Client *client, std::string &path)
}
if (client->assigned_location->autoindex == true)
_autoindex(client, path);
else
client->status = 404;
}
else
_get_file(client, path);
}
# define MAX_FILESIZE 1 * MB
# define MAX_FILESIZE 1 * MB // unused
void Webserv::_get_file(Client *client, const std::string &path)
{
/*
@@ -52,21 +55,11 @@ void Webserv::_get_file(Client *client, const std::string &path)
std::cout << "_get_file()\n";
if (access(path.c_str(), F_OK) == -1)
{
std::perror("err access()");
client->status = 404;
return ;
}
client->status = ::eval_file_mode(path, R_OK);
if (client->status)
return;
if (access(path.c_str(), R_OK) == -1)
{
std::perror("err access()");
client->status = 403;
return ;
}
ifd.open(path.c_str(), std::ios::ate);
ifd.open(path.c_str());
if (!ifd)
{
std::cerr << path << ": ifd.open fail" << '\n';
@@ -74,17 +67,6 @@ void Webserv::_get_file(Client *client, const std::string &path)
}
else
{
/* std::streampos size = ifd.tellg();
// WIP Low priority : Chunk or not chunk (if filesize too big)
if (size > MAX_FILESIZE)
{
// Then chunk
client->status = 500; // WIP temp
std::cerr << "File too large for non chunk body\n";
return ;
} */
ifd.seekg(0, std::ios::beg);
buf << ifd.rdbuf();
if (!ifd || !buf)
{
@@ -100,6 +82,19 @@ void Webserv::_get_file(Client *client, const std::string &path)
}
}
/*
// WIP Low priority : Chunk or not chunk (if filesize > MAX_FILESIZE)
// WITH flag "std::ios::ate" for open()
std::streampos size = ifd.tellg();
ifd.seekg(0, std::ios::beg);
if (size > MAX_FILESIZE)
{
// Chunked GET here
return ;
}
*/
// const?
void Webserv::_autoindex(Client *client, const std::string &path)
{