better telnet tester, merging

This commit is contained in:
Eric LAZO
2022-08-14 21:41:46 +02:00
30 changed files with 605 additions and 163 deletions

View File

@@ -21,7 +21,10 @@ void Webserv::_response(Client *client)
}
else if (ret == SEND_COMPLETE)
{
if (client->get_rq_headers("Connection") == "close" || client->status == 408)
if (client->get_rq_headers("Connection") == "close"
|| client->status == 400 // TODO: Refactoring
|| client->status == 408
|| client->status == 413)
_close_client(client->get_cl_fd());
else
{
@@ -61,32 +64,35 @@ void Webserv::_append_base_headers(Client *client)
{
client->response.append("Server: Webserv/0.1" CRLF);
if (client->get_rq_headers("Connection") == "close")
if (client->get_rq_headers("Connection") == "close"
|| client->status == 400 // TODO: Refactoring
|| client->status == 408
|| client->status == 413)
client->response.append("Connection: close" CRLF);
else
client->response.append("Connection: keep-alive" CRLF);
}
// TODO HUGO : wip
void Webserv::_construct_response(Client *client)
{
std::string path = _replace_url_root(client, client->get_rq_abs_path());
std::string path;
std::string script_output;
/* size_t pos = _cgi_pos(client, path);
if (pos != NPOS)
path = _replace_url_root(client, client->get_rq_abs_path());
if (_is_cgi(client, path))
{
client->fill_script_path(path, pos);
std::string script_output = _exec_cgi(client);
script_output = _exec_cgi(client);
_check_script_output(client, script_output);
client->response += script_output;
return;
} */
}
_process_method(client, path);
}
void Webserv::_process_method(Client *client, std::string &path)
{
std::cerr << "assigned_location->path = " << client->assigned_location->path << "\n"; // debug
std::cerr << "allow_methods = " << client->assigned_location->allow_methods << "\n"; // debug
std::cerr << "allow_methods = " << http_methods_to_str(client->assigned_location->allow_methods) << "\n"; // debug
switch (client->get_rq_method())
{
@@ -182,8 +188,6 @@ ServerConfig *_determine_process_server(Client *client, std::vector<ServerConfig
// 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';
/* RULES ***
If a path coresponds exactly to a location, use that one
@@ -206,12 +210,8 @@ If we get a url that ends in / ignore the last /
for (std::vector<LocationConfig>::const_iterator it = server.locations.begin(); it != server.locations.end(); it++)
{
// std::cout << it->path << " -- ";
if (it->path.size() > uri.size())
{
// std::cout << "skipping this one\n";
continue ;
}
if (uri.compare(0, it->path.size(), it->path) == 0)
{