fixed autoindex

This commit is contained in:
Me
2022-08-11 02:15:40 +02:00
parent c32fc2c8a2
commit 08f6929db9
2 changed files with 6 additions and 7 deletions

View File

@@ -111,9 +111,6 @@ void Webserv::_get_file(Client *client, const std::string &path)
}
}
// i only sort of need &path...
// def can improve but works for now...
//void Webserv::_autoindex(Client *client, LocationConfig &location, std::string &path)
void Webserv::_autoindex(Client *client, std::string &path)
{
std::cout << "made it to _autoindex\n";
@@ -122,24 +119,25 @@ void Webserv::_autoindex(Client *client, std::string &path)
DIR *dir;
struct dirent *ent;
// std::cout << "location root: " << client->assigned_location->root << " location path: "
// << client->assigned_location->path << '\n';
std::cout << "location root: " << client->assigned_location->root << " location path: "
<< client->assigned_location->path << '\n';
std::cout << "Path in auto is: " << path << '\n';
if ( (dir = opendir(path.c_str()) ) != NULL)
{
/* print all the files and directories within directory */
dir_list.append(AUTOINDEX_START);
dir_list.append(path);
dir_list.append(AUTOINDEX_MID1);
dir_list.append(path);
dir_list.append(AUTOINDEX_MID2);
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL)
{
std::cout << "ent: " << ent->d_name << '\n';
if (strcmp(".", ent->d_name) == 0)
continue ;
dir_list.append("<a href=\"");
// dir_list.append(path);
dir_list.append(client->assigned_location->path + "/");
dir_list.append(ent->d_name);
dir_list.append("\">");
dir_list.append(ent->d_name);