_determine_location() new version (to complete and test)
This commit is contained in:
6
memo.txt
6
memo.txt
@@ -1,11 +1,13 @@
|
|||||||
IN 42 SUBJECT, PRIORITY :
|
IN 42 SUBJECT, PRIORITY :
|
||||||
- chunked request (response not mandatory it seems)
|
|
||||||
- CGI
|
- CGI
|
||||||
|
- chunked request (response not mandatory it seems)
|
||||||
- index (default file directory)
|
- index (default file directory)
|
||||||
- Ecrire des tests !
|
- Ecrire des tests !
|
||||||
|
|
||||||
- handle redirection (weird behavior, to fix)
|
- handle redirection (weird behavior, to fix)
|
||||||
- upload files with config "upload_repo"
|
- upload files with config "upload_repo"
|
||||||
|
- _determine_location() review (New version to complete and test)
|
||||||
|
- bug with verification of "redirect uri" (valid uri are rejected)
|
||||||
-----------------------------
|
-----------------------------
|
||||||
- autoindex (done, need test)
|
- autoindex (done, need test)
|
||||||
--------------
|
--------------
|
||||||
@@ -20,8 +22,6 @@ IN 42 SUBJECT, PRIORITY :
|
|||||||
- add headers "Date" and "Last-Modified" to response
|
- add headers "Date" and "Last-Modified" to response
|
||||||
- change "std::string" to reference "std::string &" in most functions
|
- change "std::string" to reference "std::string &" in most functions
|
||||||
and add "const" if apropriate.
|
and add "const" if apropriate.
|
||||||
- Dans le parsing, trier les "locations" par ordre de precision.
|
|
||||||
Compter les "/" dans le chemin, les locations avec le plus de "/" seront en premier dans le vector.
|
|
||||||
- Il faut vérifier le path de la requête, voir si le serveur est bien censé délivrer cette ressource et si le client y a accès, avant d'appeler le CGI.
|
- Il faut vérifier le path de la requête, voir si le serveur est bien censé délivrer cette ressource et si le client y a accès, avant d'appeler le CGI.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,9 +79,6 @@ http_method str_to_http_method(std::string &str)
|
|||||||
return POST;
|
return POST;
|
||||||
else if (str == "DELETE")
|
else if (str == "DELETE")
|
||||||
return DELETE;
|
return DELETE;
|
||||||
else if (str == "ALL_METHODS") // for Eric: why this test ? can we delete it?
|
|
||||||
return ANY_METHODS;
|
|
||||||
// would prefere ALL_METHODS
|
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,21 +75,13 @@ void Webserv::_construct_response(Client *client)
|
|||||||
client->status = 413;
|
client->status = 413;
|
||||||
return;
|
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)
|
// (for codes 301, 302, 303, 307, and 308)
|
||||||
client->status = client->assigned_location->redirect_status;
|
client->status = client->assigned_location->redirect_status;
|
||||||
client->response.append("Location: ");
|
client->response.append("Location: ");
|
||||||
client->response.append(client->assigned_location->redirect_uri);
|
client->response.append(client->assigned_location->redirect_uri);
|
||||||
client->response.append(CRLF);
|
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);
|
client->response.append(CRLF);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
@@ -203,6 +195,53 @@ ServerConfig *Webserv::_determine_process_server(Client *client)
|
|||||||
return (&(*default_server));
|
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
|
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';
|
||||||
@@ -259,11 +298,11 @@ if no path coresponds then use the most correct one
|
|||||||
best = it;
|
best = it;
|
||||||
std::cout << "Picked a best! 1\n";
|
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);
|
//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 (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)
|
if (path.compare(0, it->path.size(), it->path) == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user