a few more things for location picker

This commit is contained in:
Me
2022-08-11 00:36:24 +02:00
parent 69c1a6f6bf
commit 0b51d13f13
4 changed files with 21 additions and 8 deletions

View File

@@ -232,8 +232,9 @@ void ConfigParser::_set_server_values(ServerConfig *server, \
else if (key == "root" && size == 1 && server->root == "") else if (key == "root" && size == 1 && server->root == "")
{ {
// remove trailing / // remove trailing /
if (tmp_val[0][tmp_val[0].size() - 1] == '/') if (tmp_val[0][tmp_val[0].size() - 1] != '/')
tmp_val[0].erase(tmp_val[0].size() - 1, 1); tmp_val[0].push_back('/');
// tmp_val[0].erase(tmp_val[0].size() - 1, 1);
server->root = tmp_val[0]; server->root = tmp_val[0];
} }
else if (key == "client_body_limit" && size == 1 \ else if (key == "client_body_limit" && size == 1 \
@@ -280,9 +281,10 @@ void ConfigParser::_set_location_values(LocationConfig *location, \
throw std::invalid_argument("missing value"); throw std::invalid_argument("missing value");
else if (key == "root" && size == 1 && location->root == "") else if (key == "root" && size == 1 && location->root == "")
{ {
// remove trailing / // add trailing /
if (tmp_val[0][tmp_val[0].size() - 1] == '/') if (tmp_val[0][tmp_val[0].size() - 1] != '/')
tmp_val[0].erase(tmp_val[0].size() - 1, 1); tmp_val[0].push_back('/');
// tmp_val[0].erase(tmp_val[0].size() - 1, 1);
location->root = tmp_val[0]; location->root = tmp_val[0];
} }
else if (key == "autoindex" && size == 1) else if (key == "autoindex" && size == 1)

View File

@@ -52,7 +52,8 @@ void ConfigParser::_post_processing(std::vector<ServerConfig> *servers)
if (it_l->allow_methods == UNKNOWN) if (it_l->allow_methods == UNKNOWN)
it_l->allow_methods = ANY_METHODS; it_l->allow_methods = ANY_METHODS;
if (it_l->index.empty()) // also
if (it_l->index.empty() && it_l->autoindex == false)
it_l->index = it->index; it_l->index = it->index;
// nothing to be done for cgi_ext, error_pages, redirect // nothing to be done for cgi_ext, error_pages, redirect

View File

@@ -11,12 +11,16 @@ if file, server that!
Where does cgi fit in in all this ??? Where does cgi fit in in all this ???
*/ */
std::string path = client->get_rq_abs_path(); std::string path = client->get_rq_abs_path();
// this might not be the best thing, a voir // this might not be the best thing, a voir
path.insert(0, client->assigned_location->root); // path.insert(0, client->assigned_location->root);
//client->assigned_location->path
path.replace(0, client->assigned_location->path.size(), client->assigned_location->root);
std::cerr << "path = " << path << "\n"; std::cerr << "path = " << path << "\n";
@@ -25,6 +29,9 @@ Where does cgi fit in in all this ???
// or autoindex if allowed // or autoindex if allowed
// or let _get_file sort out the error otherwise. // or let _get_file sort out the error otherwise.
// change this cuz
// if (path_is_valid(client->assigned_location->root) == 2)
// _get_file(...);
if (path_is_valid(path) == 1) if (path_is_valid(path) == 1)
{ {
// std::cout << "path is valid\n"; // std::cout << "path is valid\n";

View File

@@ -248,6 +248,9 @@ if no path coresponds then use the most correct one
if (tmp[tmp.size() - 1] != '/') if (tmp[tmp.size() - 1] != '/')
tmp.push_back('/'); tmp.push_back('/');
/test/index.html/
/test/index.html
for (std::vector<LocationConfig>::const_iterator it = server.locations.begin(); it != server.locations.end(); it++) for (std::vector<LocationConfig>::const_iterator it = server.locations.begin(); it != server.locations.end(); it++)
{ {