diff --git a/srcs/Client.cpp b/srcs/Client.cpp index 1182e5d..f4679b1 100644 --- a/srcs/Client.cpp +++ b/srcs/Client.cpp @@ -213,6 +213,8 @@ bool Client::fill_script_path(std::string script) if (pos == 0) { tmp = path.substr(0, pos + len); + _request.script.path = "./srcs" + tmp; // TODO: root path ? + _request.script.path = "./srcs" + tmp; // TODO: root path ? _request.script.info = path.substr(pos + len); return true; diff --git a/srcs/webserv/Webserv.hpp b/srcs/webserv/Webserv.hpp index ff3c986..b8e31f4 100644 --- a/srcs/webserv/Webserv.hpp +++ b/srcs/webserv/Webserv.hpp @@ -88,6 +88,10 @@ class Webserv // const LocationConfig *_determine_location(const ServerConfig &server, const std::string &path) const; std::string _determine_file_extension(const std::string &path) const; // method_get.cpp + +// move later + std::string _replace_url_root(Client *client, std::string path); + void _get(Client *client); void _get_file(Client *client, const std::string &path); void _autoindex(Client *client, std::string &path); diff --git a/srcs/webserv/method_get.cpp b/srcs/webserv/method_get.cpp index 8a9089a..20edb07 100644 --- a/srcs/webserv/method_get.cpp +++ b/srcs/webserv/method_get.cpp @@ -1,30 +1,21 @@ #include "Webserv.hpp" -// const? -void Webserv::_get(Client *client) +std::string Webserv::_replace_url_root(Client *client, std::string path) { - std::string path = client->get_rq_abs_path(); - - std::cerr << "path before = " << path << "\n"; // DEBUG + std::cerr << "path before = " << client_path << "\n"; // DEBUG if (client->assigned_location->path == "/") path.insert(0, client->assigned_location->root); else path.replace(0, client->assigned_location->path.size(), client->assigned_location->root); std::cerr << "path after = " << path << "\n"; // DEBUG + return path; +} + +// const? +void Webserv::_get(Client *client) +{ - // TMP HUGO ( We move this in process_switch() ) - // - std::string script_output; - if (_is_cgi(client)) - { - script_output = _exec_cgi(client); - _check_script_output(client, script_output); - client->response += script_output; - return; - } - // - // END TMP HUGO // Index/Autoindex block if (eval_file_type(path) == IS_DIR) diff --git a/srcs/webserv/response.cpp b/srcs/webserv/response.cpp index a2c459d..423405b 100644 --- a/srcs/webserv/response.cpp +++ b/srcs/webserv/response.cpp @@ -71,6 +71,16 @@ void Webserv::_construct_response(Client *client) { /* Switch between normal behavior or CGI here ? maybe better than in _get(), _post(), ...*/ + std::string path = _replace_url_root(client, client->get_rq_abs_path()); + + std::string script_output; + if (_is_cgi(path)) + { + script_output = _exec_cgi(client); + _check_script_output(client, script_output); + client->response += script_output; + return; + } _process_method(client); }