wip test path cgi :
- _cgi_pos seems to be ok - construct url from return is not implemented yet + renamed script with extension .php and .cpp
This commit is contained in:
@@ -19,6 +19,11 @@ server {
|
|||||||
autoindex on;
|
autoindex on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /cgi-bin {
|
||||||
|
root ./srcs/cgi-bin/;
|
||||||
|
cgi_ext cgi php txt;
|
||||||
|
}
|
||||||
|
|
||||||
location /redirect {
|
location /redirect {
|
||||||
redirect 307 https://fr.wikipedia.org/wiki/Ketchup;
|
redirect 307 https://fr.wikipedia.org/wiki/Ketchup;
|
||||||
# redirect 307 https://www.youtube.com/watch?v=rG6b8gjMEkw;
|
# redirect 307 https://www.youtube.com/watch?v=rG6b8gjMEkw;
|
||||||
|
|||||||
BIN
srcs/cgi-bin/cgi.cpp
Normal file → Executable file
BIN
srcs/cgi-bin/cgi.cpp
Normal file → Executable file
Binary file not shown.
Binary file not shown.
@@ -31,6 +31,7 @@
|
|||||||
# include "utils.hpp"
|
# include "utils.hpp"
|
||||||
# include "http_status.hpp"
|
# include "http_status.hpp"
|
||||||
# include "autoindex.hpp"
|
# include "autoindex.hpp"
|
||||||
|
# include "colors.h"
|
||||||
|
|
||||||
extern bool g_run;
|
extern bool g_run;
|
||||||
extern int g_last_signal;
|
extern int g_last_signal;
|
||||||
|
|||||||
@@ -4,18 +4,36 @@
|
|||||||
// TODO HUGO : go ameliorer la recherche comme on a dit.
|
// TODO HUGO : go ameliorer la recherche comme on a dit.
|
||||||
size_t Webserv::_cgi_pos(Client *client, std::string &path)
|
size_t Webserv::_cgi_pos(Client *client, std::string &path)
|
||||||
{
|
{
|
||||||
size_t pos = NPOS;
|
std::vector<std::string> v_ext;
|
||||||
std::vector<std::string>::const_iterator it;
|
std::vector<std::string>::const_iterator it;
|
||||||
it = client->assigned_location->cgi_ext.begin();
|
std::vector<std::string>::const_iterator it_end;
|
||||||
while (it != client->assigned_location->cgi_ext.end())
|
size_t pos = 0;
|
||||||
|
|
||||||
|
/*DEBUG*/ it = client->assigned_location->cgi_ext.begin(); std::cout << B_YELLOW << "\nDEBUG _cgi_pos()\n" << RESET << "vector_ext.size():[" << client->assigned_location->cgi_ext.size() << "]\n\n";
|
||||||
|
v_ext = client->assigned_location->cgi_ext;
|
||||||
|
if (v_ext.empty())
|
||||||
|
return NPOS;
|
||||||
|
/*DEBUG*/ std::cout << "ext:[" << *it << "]\n" << "path:[" << path << "]\n\n";
|
||||||
|
it_end = client->assigned_location->cgi_ext.end();
|
||||||
|
while (pos < path.size())
|
||||||
{
|
{
|
||||||
pos = std::min(path.find(*it) + it->size(), pos);
|
/*DEBUG*/ std::cout << "\nwhile\n";
|
||||||
++it;
|
if (path.compare(pos, 2, "./") == 0)
|
||||||
|
pos += 2;
|
||||||
|
/*DEBUG*/ std::cout << "&path[pos]:[" << &path[pos] << "]\n";
|
||||||
|
pos = path.find('.', pos);
|
||||||
|
if (pos == NPOS)
|
||||||
|
return pos;
|
||||||
|
it = client->assigned_location->cgi_ext.begin();
|
||||||
|
for ( ; it != it_end; ++it)
|
||||||
|
{
|
||||||
|
/*DEBUG*/ std::cout << " for\n"; std::cout << " &path[pos]:[" << &path[pos] << "]\n" << " *it:[" << *it << "]\n" << " (*it).size():[" << (*it).size() << "]\n" << " path.substr(pos, (*it).size()):[" << path.substr(pos + 1, (*it).size()) << "]\n\n";
|
||||||
|
if (path.compare(pos + 1, (*it).size(), *it) == 0)
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
pos++;
|
||||||
}
|
}
|
||||||
if (pos == NPOS)
|
return pos;
|
||||||
return false;
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Webserv::_exec_cgi(Client *client)
|
std::string Webserv::_exec_cgi(Client *client)
|
||||||
|
|||||||
@@ -71,15 +71,18 @@ void Webserv::_construct_response(Client *client)
|
|||||||
{
|
{
|
||||||
std::string path = _replace_url_root(client, client->get_rq_abs_path());
|
std::string path = _replace_url_root(client, client->get_rq_abs_path());
|
||||||
|
|
||||||
/* size_t pos = _cgi_pos(client, path);
|
size_t pos = _cgi_pos(client, path);
|
||||||
if (pos != NPOS)
|
//debug
|
||||||
{
|
std::cout << "pos:" << pos << B_YELLOW << "\nfin debug _cgi_pos()\n\n" << RESET;
|
||||||
client->fill_script_path(path, pos);
|
(void)pos;
|
||||||
std::string script_output = _exec_cgi(client);
|
// if (pos != NPOS)
|
||||||
_check_script_output(client, script_output);
|
// {
|
||||||
client->response += script_output;
|
// client->fill_script_path(path, pos);
|
||||||
return;
|
// std::string script_output = _exec_cgi(client);
|
||||||
} */
|
// _check_script_output(client, script_output);
|
||||||
|
// client->response += script_output;
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
_process_method(client, path);
|
_process_method(client, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user