Moved most request errors check in Client
+ bugfix of "Bad file descriptor" due to empty operator=() in Client + added a condition in _determine_location_COOP_FIX() + udpate memo.txt + need fix for index/autoindex (location "/list" dont work)
This commit is contained in:
@@ -69,22 +69,8 @@ void Webserv::_append_base_headers(Client *client)
|
||||
|
||||
void Webserv::_construct_response(Client *client)
|
||||
{
|
||||
// TODO : Move this in read(), stop read if content too large
|
||||
if (client->get_rq_body().size() > client->assigned_server->client_body_limit)
|
||||
{
|
||||
client->status = 413;
|
||||
return;
|
||||
}
|
||||
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);
|
||||
client->response.append(CRLF);
|
||||
return ;
|
||||
}
|
||||
/* Switch between normal behavior or CGI here ?
|
||||
maybe better than in _get(), _post(), ...*/
|
||||
_process_method(client);
|
||||
}
|
||||
|
||||
@@ -92,30 +78,17 @@ void Webserv::_process_method(Client *client)
|
||||
{
|
||||
std::cerr << "assigned_location->path = " << client->assigned_location->path << "\n"; // debug
|
||||
std::cerr << "allow_methods = " << client->assigned_location->allow_methods << "\n"; // debug
|
||||
if (client->get_rq_method() == UNKNOWN)
|
||||
|
||||
switch (client->get_rq_method())
|
||||
{
|
||||
client->status = 501;
|
||||
}
|
||||
else if (client->assigned_location->allow_methods & client->get_rq_method())
|
||||
{
|
||||
switch (client->get_rq_method())
|
||||
{
|
||||
case (GET):
|
||||
_get(client); break;
|
||||
case (POST):
|
||||
_post(client); break;
|
||||
case (DELETE):
|
||||
_delete(client); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
client->status = 405;
|
||||
client->response.append("Allow: ");
|
||||
client->response.append(::http_methods_to_str(client->assigned_location->allow_methods));
|
||||
client->response.append(CRLF);
|
||||
case (GET):
|
||||
_get(client); break;
|
||||
case (POST):
|
||||
_post(client); break;
|
||||
case (DELETE):
|
||||
_delete(client); break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +138,8 @@ void Webserv::_append_body(Client *client, const std::string &body, const std::s
|
||||
client->response.append(body);
|
||||
}
|
||||
|
||||
ServerConfig *Webserv::_determine_process_server(Client *client)
|
||||
// Temporary Global Scope. Probably move to Client in the future.
|
||||
ServerConfig *_determine_process_server(Client *client, std::vector<ServerConfig> &servers)
|
||||
{
|
||||
/*
|
||||
http://nginx.org/en/docs/http/request_processing.html
|
||||
@@ -174,22 +148,22 @@ ServerConfig *Webserv::_determine_process_server(Client *client)
|
||||
*/
|
||||
|
||||
std::string const &server_name = client->get_rq_headers("Host");
|
||||
std::vector<ServerConfig>::iterator it = _servers.begin();
|
||||
std::vector<ServerConfig>::iterator default_server = _servers.end();
|
||||
std::vector<ServerConfig>::iterator it = servers.begin();
|
||||
std::vector<ServerConfig>::iterator default_server = servers.end();
|
||||
|
||||
while (it != _servers.end())
|
||||
while (it != servers.end())
|
||||
{
|
||||
if (it->host == client->get_cl_lsocket()->host
|
||||
&& it->port == client->get_cl_lsocket()->port)
|
||||
{
|
||||
if ( std::find(it->server_name.begin(), it->server_name.end(), server_name) != it->server_name.end() )
|
||||
break;
|
||||
else if (default_server == _servers.end())
|
||||
else if (default_server == servers.end())
|
||||
default_server = it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
if (it != _servers.end())
|
||||
if (it != servers.end())
|
||||
return (&(*it));
|
||||
else
|
||||
return (&(*default_server));
|
||||
@@ -221,16 +195,20 @@ else
|
||||
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
|
||||
if (it->path.size() > path.size())
|
||||
{
|
||||
++it;
|
||||
continue;
|
||||
// prendre en compte l'éventuel "/" final si location est un dossier
|
||||
if (it->path.size()-1 > path.size() || it->path[it->path.size()-1] != '/')
|
||||
{
|
||||
++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() - 1] == '/')
|
||||
else if (path[it->path.size()-1] == '/')
|
||||
break;
|
||||
}
|
||||
++it;
|
||||
@@ -241,8 +219,8 @@ else
|
||||
return (&(server.locations.back()));
|
||||
}
|
||||
|
||||
|
||||
const LocationConfig *Webserv::_determine_location(const ServerConfig &server, const std::string &path) const
|
||||
// Temporary Global Scope. Probably move to Client in the future.
|
||||
const LocationConfig *_determine_location(const ServerConfig &server, const std::string &path)
|
||||
{
|
||||
std::cout << "determin location path sent: " << path << '\n';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user