cgi_ext, redirect and upload_repo now functional in config, fixed location picker, some cleanup

This commit is contained in:
Me
2022-08-09 02:37:28 +02:00
parent a44b9b493a
commit 97c90236b9
7 changed files with 79 additions and 47 deletions

View File

@@ -171,25 +171,58 @@ ServerConfig *Webserv::_determine_process_server(Client *client)
const LocationConfig *Webserv::_determine_location(const ServerConfig &server, const std::string &path) const
{
// std::cout << "determin location path sent: " << path << '\n';
std::cout << "determin location path sent: " << path << '\n';
std::vector<LocationConfig>::const_iterator it = server.locations.begin();
while (it != server.locations.end())
/// NO FUCKING IDEA WHY BUT...
// basically if 2 strings are identical to a point, compare from
// longer one or it'll freak out cuz of \0 or something idk
//// Basically: str.compare() from the larger string...
/* RULES ***
If a path coresponds exactly to a location, use that one
if no path coresponds then use the most correct one
most correct means the most precise branch that is still above
the point we are aiming for
*/
std::vector<LocationConfig>::const_iterator best;
std::cout << "\nMade it to weird location picker case.\n";
for (std::vector<LocationConfig>::const_iterator it = server.locations.begin(); it != server.locations.end(); it++)
{
// std::cout << it->path << " -- ";
// if (it->path.compare(0, path.size(), path) == 0)
if (it->path.compare(0, it->path.size(), path) == 0)
break;
// kinda gross i know but... have to deal with when there's a / at the end
if (it->path[it->path.size() - 1] == '/' \
std::cout << it->path << " -- ";
// if (rit->path.size() > path.size())
/* if ((rit->path[rit->path.size() - 1] == '/' ? rit->path.size() : rit->path.size() - 1) > path.size())
{
std::cout << "skipping this one\n";
continue ;
}
*/
// OK I REALLY DON"T LOVE THIS PART, BUT IT DOES WORK FOR NOW...
// if (it->path[it->path.size() - 1] == '/'
// && it->path.compare(0, it->path.size(), path + "/") == 0)
// HOLD ON THIS MIGHT BE GOOD, BUT I COULD USE SOME HELP...
if (it->path[it->path.size() - 1] == '/'
&& it->path.compare(0, it->path.size() - 1, path) == 0)
break;
++it;
{
best = it;
std::cout << "Picked a best! 1\n";
}
// int comp = path.compare(0, rit->path.size(), rit->path);
//int comp = rit->path.compare(0, rit->path.size() - 1, path);
// std::cout << "rit path size: " << rit->path.size() << " comp: " << comp << '\n';
// if (rit->path.compare(0, rit->path.size(), path) == 0)
// if (comp == 0)
if (path.compare(0, it->path.size(), it->path) == 0)
{
best = it;
std::cout << "Picked a best! 2\n";
}
}
if (it != server.locations.end())
return (&(*it));
else
return (&(server.locations.back()));
return (&(*best));
}
std::string Webserv::_determine_file_extension(const std::string &path) const