diff --git a/default.config b/default.config index 0dfc61b..abf9e92 100644 --- a/default.config +++ b/default.config @@ -36,8 +36,7 @@ server { redirect 301 https://berniesanders.com/404/; } - # /stylesheet/ alone doesn't work, i mean we don't have wildcards... - location /stylesheet/style.css { + location /stylesheet/ { # root ./www/../; root ./; } @@ -46,9 +45,6 @@ server { # allow_methods DELETE; } -# location /something/long/here { -# } - location /test/test_deeper/ { # allow_methods autoindex on; @@ -63,10 +59,4 @@ server { # } -# ok in theory if one were to go to /test they would get the index in www -# as opposed to the one in /website... -# location /test { -# root /www; -# } - } diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index 36435c7..c7e8109 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -238,26 +238,52 @@ if no path coresponds then use the most correct one the point we are aiming for */ + +// IS THERE A WAY TO SIMPLIFY THIS LOGIC ??? + +// what if i tack on a / at the end of path if there isn't one +// and then compare it to things that are their normal length? + + std::string tmp = path; + if (tmp[tmp.size() - 1] != '/') + tmp.push_back('/'); + + for (std::vector::const_iterator it = server.locations.begin(); it != server.locations.end(); it++) { std::cout << it->path << " -- "; + + if (it->path.size() > tmp.size()) + continue ; + + if (tmp.compare(0, it->path.size(), it->path) == 0) + { + std::cout << "checking with last /\n"; + if (it->path.size() == tmp.size()) + { + std::cout << "path sizes are equal \n"; + return (&(*it)); + } + else if (tmp[it->path.size() - 1] == '/') + { + std::cout << "ends in /\n"; + return (&(*it)); + } + } + +/* // 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] == '/') @@ -300,6 +326,13 @@ if no path coresponds then use the most correct one } } } +*/ + + } +// if (it != server.locations.end()) +// return (&(*it)); +// else + return (&(server.locations.back())); // /test/mdr // /test/mdr/ // /test/mdrBST @@ -320,68 +353,8 @@ if no path coresponds then use the most correct one - } -// if (it != server.locations.end()) -// return (&(*it)); -// else - return (&(server.locations.back())); -/* - - std::vector::const_iterator best; - std::cout << "\nMade it to weird location picker case.\n"; - - for (std::vector::const_iterator it = server.locations.begin(); it != server.locations.end(); it++) - { -*/ - // 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... - -//test /test/ - -//test/redirect/index /test/redirect -//test/redirec_something - -// thing is reverse sorted -// if location path is longer than path sent, don't look at it -// otherwise compare if (path.compare(0, it->path.size(), it->path) == 0) -// do another size compare and look for / if location smaller than client otherwise /redirect_something /redirect - -// compare everything -// - -/* if (it->path[it->path.size() - 1] == '/' - && it->path.compare(0, it->path.size() - 1, path) == 0) - { - 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"; - } - } -// //test.comare(0, 5, /test/something) - // /test /test/something - return (&(*best)); -*/ } std::string Webserv::_determine_file_extension(const std::string &path) const