fixed autoindex
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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()));
|
||||||
|
|||||||
Reference in New Issue
Block a user