_determine_location() new version (to complete and test)

This commit is contained in:
LuckyLaszlo
2022-08-09 20:47:21 +02:00
parent 56f4cf7e15
commit 1eb989a3fd
3 changed files with 55 additions and 19 deletions

View File

@@ -75,21 +75,13 @@ void Webserv::_construct_response(Client *client)
client->status = 413;
return;
}
/* if (client->assigned_location->redirect_status)
{
if (client->assigned_location->redirect_status)
{ // Weird behavior. Sometimes, the web browser seems to wait for a complete response until timeout.
// (for codes 301, 302, 303, 307, and 308)
client->status = client->assigned_location->redirect_status;
client->response.append("Location: ");
client->response.append(client->assigned_location->redirect_uri);
client->response.append(CRLF);
} */
if (client->get_rq_abs_path().find("redirect_test") != std::string::npos) // Test block
{ // Weird behavior. The web browser seems to wait for a complete response until timeout.
// (for codes 301, 302, 303, 307, and 308)
client->status = 307;
client->response.append("Location: ");
client->response.append("https://www.rfc-editor.org/rfc/rfc3875#section-3.3");
client->response.append(CRLF);
client->response.append(CRLF);
return ;
}
@@ -203,6 +195,53 @@ ServerConfig *Webserv::_determine_process_server(Client *client)
return (&(*default_server));
}
const LocationConfig *_determine_location_COOP_FIX(const ServerConfig &server, const std::string &path)
{
/* Pseudo-code :
- comparer les size(), si location.path > client.path, stop comparaison.
- client.path.compare(0, location.path.size(), location.path)
if ( == 0)
{
if (location.path.size() == client.path.size())
{
FOUND;
}
else if (client.path[location.path.size()] == '/')
{
FOUND;
}
}
else
{
NOT FOUND;
++next;
}
*/
std::vector<LocationConfig>::const_iterator it = server.locations.begin();
while (it != server.locations.end())
{
if (it->path.size() > path.size()) // Warning : il faut aussi prendre en compte l'éventuel "/" final
{
++it;
continue;
}
if (path.compare(0, it->path.size(), it->path) == 0)
{
if (it->path.size() == path.size())
break;
else if (path[it->path.size()] == '/')
break;
}
++it;
}
if (it != server.locations.end())
return (&(*it));
else
return (&(server.locations.back()));
}
const LocationConfig *Webserv::_determine_location(const ServerConfig &server, const std::string &path) const
{
std::cout << "determin location path sent: " << path << '\n';
@@ -259,11 +298,11 @@ if no path coresponds then use the most correct one
best = it;
std::cout << "Picked a best! 1\n";
}
int comp = path.compare(0, rit->path.size(), rit->path);
// 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';
// 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 (comp == 0)
if (path.compare(0, it->path.size(), it->path) == 0)
{