DELETE method tested and fixed
+ added 404 for directories without index and autoindex + minors adjustements
This commit is contained in:
@@ -5,10 +5,9 @@
|
||||
void Webserv::_post(Client *client, const std::string &path)
|
||||
{
|
||||
/*
|
||||
WIP
|
||||
https://www.rfc-editor.org/rfc/rfc9110.html#name-post
|
||||
*/
|
||||
(void)path;
|
||||
(void)path; // unused, we use "assigned_location->upload_dir" instead
|
||||
std::cout << "_post()\n";
|
||||
std::cerr << "upload_dir = " << client->assigned_location->upload_dir << "\n";
|
||||
|
||||
@@ -31,12 +30,17 @@ void Webserv::_post(Client *client, const std::string &path)
|
||||
// TODO : Loop for multi body
|
||||
void Webserv::_upload_files(Client *client)
|
||||
{
|
||||
std::cout << "_upload_files()\n";
|
||||
std::ofstream ofd;
|
||||
std::vector<MultipartBody>::const_iterator body_it = client->get_rq_multi_bodys().begin();
|
||||
std::string path;
|
||||
std::string filename;
|
||||
size_t pos;
|
||||
bool file_existed;
|
||||
bool file_existed = false;
|
||||
|
||||
client->status = ::eval_file_mode(client->assigned_location->upload_dir, W_OK);
|
||||
if (client->status)
|
||||
return;
|
||||
|
||||
while (body_it != client->get_rq_multi_bodys().end())
|
||||
{
|
||||
@@ -72,13 +76,13 @@ void Webserv::_upload_files(Client *client)
|
||||
path.append(filename);
|
||||
|
||||
|
||||
if (access(path.c_str(), F_OK) == -1)
|
||||
if (::access(path.c_str(), F_OK) == -1)
|
||||
file_existed = false;
|
||||
else
|
||||
file_existed = true;
|
||||
|
||||
// How to determine status 403 for file that dont already exist ? access() on the upload_dir ?
|
||||
if (file_existed && access(path.c_str(), W_OK) == -1)
|
||||
if (file_existed && ::access(path.c_str(), W_OK) == -1)
|
||||
{
|
||||
std::perror("err access()");
|
||||
client->status = 403;
|
||||
@@ -103,10 +107,15 @@ void Webserv::_upload_files(Client *client)
|
||||
ofd.close();
|
||||
}
|
||||
|
||||
client->status = 204;
|
||||
client->response.append(CRLF);
|
||||
// https://www.rfc-editor.org/rfc/rfc9110.html#name-204-no-content
|
||||
}
|
||||
|
||||
/*
|
||||
if (file_existed) // with multi body it doesn't make much sense
|
||||
{
|
||||
// client->status = 200;
|
||||
client->status = 204; // DEBUG 204
|
||||
client->status = 200;
|
||||
client->response.append("Location: ");
|
||||
client->response.append("/index.html"); // WIP
|
||||
client->response.append(CRLF);
|
||||
@@ -115,12 +124,11 @@ void Webserv::_upload_files(Client *client)
|
||||
}
|
||||
else
|
||||
{
|
||||
// client->status = 201;
|
||||
client->status = 204; // DEBUG 204
|
||||
client->status = 201;
|
||||
client->response.append("Location: ");
|
||||
client->response.append("/index.html"); // WIP
|
||||
client->response.append(CRLF);
|
||||
client->response.append(CRLF);
|
||||
// WIP https://www.rfc-editor.org/rfc/rfc9110.html#section-9.3.3-4
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user