DELETE method tested and fixed
+ added 404 for directories without index and autoindex + minors adjustements
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
void Webserv::_delete(Client *client, const std::string &path)
|
||||
{
|
||||
/*
|
||||
WIP
|
||||
https://www.rfc-editor.org/rfc/rfc9110.html#name-delete
|
||||
*/
|
||||
_delete_file(client, path);
|
||||
@@ -12,24 +11,21 @@ void Webserv::_delete(Client *client, const std::string &path)
|
||||
|
||||
void Webserv::_delete_file(Client *client, const std::string &path)
|
||||
{
|
||||
if (access(path.c_str(), F_OK) == -1)
|
||||
{
|
||||
std::perror("err access()");
|
||||
client->status = 404;
|
||||
return ;
|
||||
}
|
||||
std::cout << "_delete_file()\n";
|
||||
client->status = ::eval_file_mode(path, W_OK);
|
||||
if (client->status)
|
||||
return;
|
||||
|
||||
if (access(path.c_str(), W_OK) == -1)
|
||||
{
|
||||
std::perror("err access()");
|
||||
client->status = 403;
|
||||
return ;
|
||||
}
|
||||
|
||||
if (remove(path.c_str()) == -1)
|
||||
if (std::remove(path.c_str()) == -1)
|
||||
{
|
||||
std::perror("err remove()");
|
||||
client->status = 500;
|
||||
if (errno == ENOTEMPTY || errno == EEXIST)
|
||||
client->status = 403;
|
||||
else
|
||||
client->status = 500;
|
||||
return ;
|
||||
}
|
||||
|
||||
client->status = 204;
|
||||
client->response.append(CRLF);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user