mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 13:27:59 +03:00
fix: cgi exe
This commit is contained in:
@@ -162,9 +162,6 @@ std::string Client::generateRespons(void)
|
||||
_to_send_char = new char[len + 1];
|
||||
std::memcpy(_to_send_char, _toSend.c_str(), len + 1);
|
||||
|
||||
// DBOUT << "len = " << len << ENDL;
|
||||
// DBOUT << "strlen = " << strlen(_to_send_char) << ENDL;
|
||||
// DBOUT << "content_lenth = " << _request.getContentLength() << ENDL;
|
||||
return (_toSend);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,21 @@ int isDir(std::string path)
|
||||
return (-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
void copyLocation(location *dest, location *src)
|
||||
{
|
||||
dest->autoindex = src->autoindex;
|
||||
dest->cgi_pass = src->cgi_pass;
|
||||
dest->clientBodySize = src->clientBodySize;
|
||||
dest->directoryFile = src->directoryFile;
|
||||
dest->location = src->location;
|
||||
dest->methods = src->methods;
|
||||
dest->redirect = src->redirect;
|
||||
dest->root = src->root;
|
||||
dest->uploadAccept = src->uploadAccept;
|
||||
dest->uploadDir = src->uploadDir;
|
||||
}
|
||||
|
||||
int Config::calcLen(std::string &s1, std::string &s2)
|
||||
{
|
||||
unsigned long len = 0;
|
||||
@@ -68,7 +83,12 @@ location *Config::getLocation(std::vector<location *> &arr, std::string &URI)
|
||||
tmp = *it;
|
||||
tryLocation = URI.substr(0, tryLen);
|
||||
if (tmp->location == tryLocation)
|
||||
{
|
||||
tmp = new location;
|
||||
copyLocation(tmp, *it);
|
||||
step_1.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
if (!step_1.empty())
|
||||
@@ -91,6 +111,8 @@ location *Config::getLocation(std::vector<location *> &arr, std::string &URI)
|
||||
suffix1 = tmp->location.substr(2);
|
||||
if (suffix1 == suffix)
|
||||
{
|
||||
tmp = new location;
|
||||
copyLocation(tmp, *it);
|
||||
step_2.push_back(tmp);
|
||||
break;
|
||||
}
|
||||
@@ -104,6 +126,7 @@ location *Config::getLocation(std::vector<location *> &arr, std::string &URI)
|
||||
if(!step_2[1]->cgi_pass.empty())
|
||||
{
|
||||
step_2[0]->cgi_pass = step_2[1]->cgi_pass;
|
||||
delete step_2[1];
|
||||
}
|
||||
return (step_2[0]);
|
||||
}
|
||||
|
||||
@@ -107,11 +107,11 @@ ssize_t Response::getMaxBodySize(void)
|
||||
{
|
||||
return (_maxBodySize);
|
||||
}
|
||||
|
||||
//-------------------------------------------------File---------------------------------------
|
||||
|
||||
void Response::OpenResponseFile(const char *path)
|
||||
{
|
||||
DBOUT << "in OPEN RESPONSE FILE " << path << ENDL;
|
||||
std::stringstream ss;
|
||||
std::ifstream file(path, std::ifstream::in);
|
||||
|
||||
@@ -213,11 +213,8 @@ std::string Response::getFullURI(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
DBOUT << "location" << _location->location << ENDL;
|
||||
tmp = _request.getURI().substr(len);
|
||||
DBOUT << "tmp1 " << RED << tmp << ENDL;
|
||||
tmp = _location->root + tmp;
|
||||
DBOUT << "tmp2" << RED << tmp << ENDL;
|
||||
}
|
||||
if (_request.isDir(tmp) == 0)
|
||||
{
|
||||
@@ -327,16 +324,9 @@ void Response::generate2(serverListen &l)
|
||||
_method = _request.getMethod();
|
||||
_maxBodySize = (_location->clientBodySize > 0) ? _location->clientBodySize : _config->getClientBodySize();
|
||||
if (_maxBodySize > 0)
|
||||
_code = (_request.getRecved() > _maxBodySize) ? 413 : _code;
|
||||
DBOUT << BLUE << "max size" << _maxBodySize << ENDL;
|
||||
DBOUT << BLUE << "_location size" << _location->clientBodySize << ENDL;
|
||||
DBOUT << BLUE << "_config sieze" << _config->getClientBodySize() << ENDL;
|
||||
DBOUT << BLUE << "req size " << _request.getContentLength() << ENDL;
|
||||
DBOUT << BLUE << "recv size " << _request.getRecved() << ENDL;
|
||||
_code = (_request.getBody().size() > (unsigned long)_maxBodySize) ? 413 : _code;
|
||||
}
|
||||
|
||||
DBOUT << "fullURI " << _fullURI << ENDL;
|
||||
DBOUT << RED << "code is " << _code << ENDL;
|
||||
if (_request.badCode(_code) || (!allowedMethod(_method) && _location->cgi_pass.empty()) || isRedirect())
|
||||
{
|
||||
invalidClient();
|
||||
@@ -384,6 +374,7 @@ void Response::methodGet(void)
|
||||
CgiHandle cgi(_request, *this);
|
||||
|
||||
_body = cgi.executeCgi();
|
||||
|
||||
unsigned long pos = _body.find("\r\n\r\n");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
@@ -410,6 +401,7 @@ void Response::methodPost(void)
|
||||
CgiHandle cgi(_request, *this);
|
||||
|
||||
_body = cgi.executeCgi();
|
||||
DBOUT << "CGI SIZE BODY " << _body.size() << ENDL;
|
||||
unsigned long pos = _body.find("\r\n\r\n");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
@@ -558,4 +550,5 @@ std::string Response::getErrorPage(int code)
|
||||
|
||||
Response::~Response()
|
||||
{
|
||||
delete _location;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ private:
|
||||
std::map<int, std::string> _errorPages;
|
||||
bool _Autoindex;
|
||||
serverListen _hostPort;
|
||||
std::string _fullURI;
|
||||
std::string _method;
|
||||
|
||||
private:
|
||||
@@ -73,6 +72,7 @@ public:
|
||||
void setData(Request, ServerConfig *);
|
||||
void setData(Request &, ServerConfig *, location *location);
|
||||
public:
|
||||
std::string _fullURI;
|
||||
void OpenResponseFile(const char *path);
|
||||
void OpenErrorFile(int code);
|
||||
void initErrorCode(void);
|
||||
|
||||
Reference in New Issue
Block a user