started non hardcoded cgi call
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user