a few small fixes here and there, more telnet tests, starting Siege load testing
This commit is contained in:
@@ -361,6 +361,8 @@ void Client::_parse_request_target( std::string target )
|
||||
else
|
||||
_request.query = "";
|
||||
_request.abs_path = target.substr(0, pos);
|
||||
if (_request.abs_path[_request.abs_path.size() - 1] == '/')
|
||||
_request.abs_path.erase(_request.abs_path.size() - 1);
|
||||
}
|
||||
|
||||
void Client::_parse_request_fields()
|
||||
|
||||
@@ -50,14 +50,6 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
|
||||
&& it_l->path.size() > 1)
|
||||
it_l->path.erase(it_l->path.size() - 1);
|
||||
|
||||
std::vector<LocationConfig>::const_iterator tmp = it_l + 1;
|
||||
while (tmp != it->locations.end())
|
||||
{
|
||||
if (it_l->path == tmp->path)
|
||||
throw std::invalid_argument("Duplicate locations in config file");
|
||||
++tmp;
|
||||
}
|
||||
|
||||
if (it_l->root == "")
|
||||
it_l->root = it->root;
|
||||
|
||||
@@ -71,6 +63,20 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
|
||||
|
||||
++it_l;
|
||||
}
|
||||
|
||||
it_l = it->locations.begin();
|
||||
while (it_l != it->locations.end())
|
||||
{
|
||||
std::vector<LocationConfig>::const_iterator tmp = it_l + 1;
|
||||
while (tmp != it->locations.end())
|
||||
{
|
||||
if (it_l->path == tmp->path)
|
||||
throw std::invalid_argument("Duplicate locations in config file");
|
||||
++tmp;
|
||||
}
|
||||
++it_l;
|
||||
}
|
||||
|
||||
std::sort(it->locations.begin(), it->locations.end());
|
||||
std::reverse(it->locations.begin(), it->locations.end());
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ void Webserv::_get(Client *client, std::string &path)
|
||||
{
|
||||
path.append(client->assigned_location->index[i]);
|
||||
_get_file(client, path);
|
||||
std::cerr << "Added an index\n"; //debug
|
||||
return ;
|
||||
}
|
||||
}
|
||||
@@ -88,16 +89,10 @@ void Webserv::_autoindex(Client *client, const std::string &path)
|
||||
{
|
||||
std::cout << "_autoindex()\n";
|
||||
|
||||
// std::cout << "client target: " << client->get_rq_target() << '\n';
|
||||
|
||||
|
||||
|
||||
std::string dir_list;
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
|
||||
// std::cout << "location root: " << client->assigned_location->root << " location path: " << client->assigned_location->path << '\n';
|
||||
|
||||
// std::cout << "Path in auto is: " << path << '\n';
|
||||
if ( (dir = opendir(path.c_str()) ) != NULL)
|
||||
{
|
||||
@@ -106,20 +101,19 @@ void Webserv::_autoindex(Client *client, const std::string &path)
|
||||
dir_list.append(AUTOINDEX_MID1);
|
||||
dir_list.append(path);
|
||||
dir_list.append(AUTOINDEX_MID2);
|
||||
/* print all the files and directories within directory */
|
||||
while ((ent = readdir (dir)) != NULL)
|
||||
{
|
||||
// std::cout << "ent: " << ent->d_name << '\n';
|
||||
if (strcmp(".", ent->d_name) == 0)
|
||||
continue ;
|
||||
dir_list.append("<a style=\"font-size:1.5em\" href=\"");
|
||||
// dir_list.append(client->get_rq_target());
|
||||
dir_list.append(client->get_rq_abs_path());
|
||||
if (dir_list[dir_list.size() - 1] != '/')
|
||||
dir_list.push_back('/');
|
||||
dir_list.append(ent->d_name);
|
||||
dir_list.append("\">");
|
||||
dir_list.append(ent->d_name);
|
||||
if (ent->d_type == DT_DIR)
|
||||
dir_list.append("/");
|
||||
dir_list.append("</a>");
|
||||
dir_list.append("\n");
|
||||
}
|
||||
@@ -131,15 +125,14 @@ void Webserv::_autoindex(Client *client, const std::string &path)
|
||||
// <a href="/test/test_deeper/..">..</a>
|
||||
|
||||
dir_list.append(AUTOINDEX_END);
|
||||
// std::cout << "\n\n" << dir_list << '\n';
|
||||
closedir (dir);
|
||||
client->status = 200;
|
||||
_append_body(client, dir_list, "html");
|
||||
}
|
||||
else
|
||||
{
|
||||
// in theory not possible cuz we already checked...
|
||||
std::cerr << "could not open dir\n";
|
||||
// throw?
|
||||
client->status = 500;
|
||||
perror("could not open dir");
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ void Webserv::_construct_response(Client *client)
|
||||
void Webserv::_process_method(Client *client, std::string &path)
|
||||
{
|
||||
std::cerr << "allow_methods = " << http_methods_to_str(client->assigned_location->allow_methods) << "\n"; // debug
|
||||
std::cerr << "Path again: " << path << '\n'; // debug
|
||||
|
||||
switch (client->get_rq_method())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user