From 0b51d13f138cfea9323a4c3a9ea28e3b7b729b74 Mon Sep 17 00:00:00 2001 From: Me Date: Thu, 11 Aug 2022 00:36:24 +0200 Subject: [PATCH] a few more things for location picker --- srcs/config/parser.cpp | 12 +++++++----- srcs/config/postProcessing.cpp | 3 ++- srcs/webserv/method_get.cpp | 11 +++++++++-- srcs/webserv/response.cpp | 3 +++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/srcs/config/parser.cpp b/srcs/config/parser.cpp index 94445bd..90ec1e1 100644 --- a/srcs/config/parser.cpp +++ b/srcs/config/parser.cpp @@ -232,8 +232,9 @@ void ConfigParser::_set_server_values(ServerConfig *server, \ else if (key == "root" && size == 1 && server->root == "") { // remove trailing / - if (tmp_val[0][tmp_val[0].size() - 1] == '/') - tmp_val[0].erase(tmp_val[0].size() - 1, 1); + if (tmp_val[0][tmp_val[0].size() - 1] != '/') + tmp_val[0].push_back('/'); + // tmp_val[0].erase(tmp_val[0].size() - 1, 1); server->root = tmp_val[0]; } 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"); else if (key == "root" && size == 1 && location->root == "") { - // remove trailing / - if (tmp_val[0][tmp_val[0].size() - 1] == '/') - tmp_val[0].erase(tmp_val[0].size() - 1, 1); + // add trailing / + if (tmp_val[0][tmp_val[0].size() - 1] != '/') + tmp_val[0].push_back('/'); +// tmp_val[0].erase(tmp_val[0].size() - 1, 1); location->root = tmp_val[0]; } else if (key == "autoindex" && size == 1) diff --git a/srcs/config/postProcessing.cpp b/srcs/config/postProcessing.cpp index 544d0a4..938c1bf 100644 --- a/srcs/config/postProcessing.cpp +++ b/srcs/config/postProcessing.cpp @@ -52,7 +52,8 @@ void ConfigParser::_post_processing(std::vector *servers) if (it_l->allow_methods == UNKNOWN) 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; // nothing to be done for cgi_ext, error_pages, redirect diff --git a/srcs/webserv/method_get.cpp b/srcs/webserv/method_get.cpp index 7c97cc5..933d141 100644 --- a/srcs/webserv/method_get.cpp +++ b/srcs/webserv/method_get.cpp @@ -11,12 +11,16 @@ if file, server that! Where does cgi fit in in all this ??? - */ + std::string path = client->get_rq_abs_path(); // 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"; @@ -25,6 +29,9 @@ Where does cgi fit in in all this ??? // or autoindex if allowed // 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) { // std::cout << "path is valid\n"; diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index c7e8109..f0b7a92 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -248,6 +248,9 @@ if no path coresponds then use the most correct one if (tmp[tmp.size() - 1] != '/') tmp.push_back('/'); +/test/index.html/ +/test/index.html + for (std::vector::const_iterator it = server.locations.begin(); it != server.locations.end(); it++) {