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) void Webserv::_autoindex(Client *client, std::string &path)
{ {
std::cout << "made it to _autoindex\n"; std::cout << "made it to _autoindex\n";
@@ -122,24 +119,25 @@ void Webserv::_autoindex(Client *client, std::string &path)
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
// std::cout << "location root: " << client->assigned_location->root << " location path: " std::cout << "location root: " << client->assigned_location->root << " location path: "
// << client->assigned_location->path << '\n'; << client->assigned_location->path << '\n';
std::cout << "Path in auto is: " << path << '\n'; std::cout << "Path in auto is: " << path << '\n';
if ( (dir = opendir(path.c_str()) ) != NULL) if ( (dir = opendir(path.c_str()) ) != NULL)
{ {
/* print all the files and directories within directory */
dir_list.append(AUTOINDEX_START); dir_list.append(AUTOINDEX_START);
dir_list.append(path); dir_list.append(path);
dir_list.append(AUTOINDEX_MID1); dir_list.append(AUTOINDEX_MID1);
dir_list.append(path); dir_list.append(path);
dir_list.append(AUTOINDEX_MID2); dir_list.append(AUTOINDEX_MID2);
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) while ((ent = readdir (dir)) != NULL)
{ {
std::cout << "ent: " << ent->d_name << '\n';
if (strcmp(".", ent->d_name) == 0) if (strcmp(".", ent->d_name) == 0)
continue ; continue ;
dir_list.append("<a href=\""); 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(ent->d_name);
dir_list.append("\">"); dir_list.append("\">");
dir_list.append(ent->d_name); dir_list.append(ent->d_name);

View File

@@ -209,6 +209,7 @@ If we get a url that ends in / ignore the last /
return (&(*it)); return (&(*it));
else if (uri[it->path.size()] == '/') else if (uri[it->path.size()] == '/')
return (&(*it)); return (&(*it));
// this works cuz only ever looking for a / burried in a longer path
} }
} }
return (&(server.locations.back())); return (&(server.locations.back()));