location picker works, needs to be tested more tho
This commit is contained in:
@@ -230,7 +230,7 @@ else
|
||||
{
|
||||
if (it->path.size() == path.size())
|
||||
break;
|
||||
else if (path[it->path.size()] == '/')
|
||||
else if (path[it->path.size() - 1] == '/')
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
@@ -260,13 +260,103 @@ if no path coresponds then use the most correct one
|
||||
the point we are aiming for
|
||||
|
||||
*/
|
||||
for (std::vector<LocationConfig>::const_iterator it = server.locations.begin(); it != server.locations.end(); it++)
|
||||
{
|
||||
std::cout << it->path << " -- ";
|
||||
// std::cout << it->path[it->path.size() - 1] << " ";
|
||||
// it->path.size() -1 only when path ends in / because
|
||||
// if path doesn't end in / then we are looking for a file
|
||||
// meaning all it->paths that end in / are wrong if they >=
|
||||
// if (it->path[it->path.size() - 1] == '/' ? it->path.size() - 1 > path.size() : it->path.size() > path.size())
|
||||
if (path[path.size() - 1] == '/' ? it->path.size() > path.size() : it->path.size() - 1 > path.size())
|
||||
{
|
||||
std::cout << "skipping this one\n";
|
||||
continue ;
|
||||
}
|
||||
|
||||
// if (it->path.size() > path.size()) // Warning : il faut aussi prendre en compte l'éventuel "/" final
|
||||
// continue;
|
||||
|
||||
|
||||
// IS THERE A WAY TO SIMPLIFY THIS LOGIC ???
|
||||
|
||||
|
||||
// if (it->path[it->path.size() - 1] == '/')
|
||||
if (path[path.size() - 1] == '/')
|
||||
{
|
||||
if (path.compare(0, it->path.size(), it->path) == 0)
|
||||
{
|
||||
std::cout << "checking with last /\n";
|
||||
if (it->path.size() == path.size())
|
||||
{
|
||||
std::cout << "path sizes are equal \n";
|
||||
return (&(*it));
|
||||
}
|
||||
else if (path[it->path.size() - 1] == '/')
|
||||
{
|
||||
std::cout << "ends in /\n";
|
||||
return (&(*it));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (path.size() < it->path.size())
|
||||
{
|
||||
std::cout << "path is missing a /\n";
|
||||
if (it->path.compare(0, path.size(), path) == 0)
|
||||
return (&(*it));
|
||||
// means we are looking for /test/test_deeper/
|
||||
// with /test/test_deeper
|
||||
}
|
||||
else
|
||||
{
|
||||
// if (it->path.compare(0, it->path.size() - 1, path) == 0)
|
||||
if (path.compare(0, it->path.size(), it->path) == 0)
|
||||
{
|
||||
std::cout << "checking without last /\n";
|
||||
if (it->path.size() - 1 == path.size())
|
||||
return (&(*it));
|
||||
else if (path[it->path.size() - 1] == '/')
|
||||
return (&(*it));
|
||||
}
|
||||
}
|
||||
}
|
||||
// /test/mdr
|
||||
// /test/mdr/
|
||||
// /test/mdrBST
|
||||
|
||||
/* More stuff to check this still works with ***
|
||||
|
||||
/test/test_
|
||||
/test/test_/
|
||||
/test/test_deeper
|
||||
/test/test_deeper/
|
||||
/test/test_deepei
|
||||
/test/test_deepei/
|
||||
/test/test_deeperi
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
// if (it != server.locations.end())
|
||||
// return (&(*it));
|
||||
// else
|
||||
return (&(server.locations.back()));
|
||||
|
||||
|
||||
/*
|
||||
|
||||
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 (rit->path.size() > path.size())
|
||||
/* if ((rit->path[rit->path.size() - 1] == '/' ? rit->path.size() : rit->path.size() - 1) > path.size())
|
||||
{
|
||||
@@ -292,7 +382,7 @@ if no path coresponds then use the most correct one
|
||||
// compare everything
|
||||
//
|
||||
|
||||
if (it->path[it->path.size() - 1] == '/'
|
||||
/* if (it->path[it->path.size() - 1] == '/'
|
||||
&& it->path.compare(0, it->path.size() - 1, path) == 0)
|
||||
{
|
||||
best = it;
|
||||
@@ -313,6 +403,7 @@ if no path coresponds then use the most correct one
|
||||
// //test.comare(0, 5, /test/something)
|
||||
// /test /test/something
|
||||
return (&(*best));
|
||||
*/
|
||||
}
|
||||
|
||||
std::string Webserv::_determine_file_extension(const std::string &path) const
|
||||
|
||||
Reference in New Issue
Block a user