mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 13:27:59 +03:00
fix: find full URI
This commit is contained in:
@@ -91,6 +91,7 @@ void Response::setCacheControl(void)
|
|||||||
|
|
||||||
void Response::OpenResponseFile(const char *path)
|
void Response::OpenResponseFile(const char *path)
|
||||||
{
|
{
|
||||||
|
DBOUT << "in OPEN RESPONSE FILE " << path << ENDL;
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
std::ifstream file(path, std::ifstream::in);
|
std::ifstream file(path, std::ifstream::in);
|
||||||
|
|
||||||
@@ -180,34 +181,26 @@ std::string Response::getTime(void)
|
|||||||
|
|
||||||
std::string Response::getFullURI(void)
|
std::string Response::getFullURI(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
bool end = false;
|
|
||||||
std::string ret = "";
|
std::string ret = "";
|
||||||
|
int len = _location->location.size();
|
||||||
|
tmp = _request.getURI().substr(len);
|
||||||
|
|
||||||
if (!_location->directoryFile.empty())
|
tmp = _location->root + tmp;
|
||||||
{
|
|
||||||
struct dirent *dirEnt;
|
|
||||||
DIR *dir = opendir(_location->root.c_str());
|
|
||||||
|
|
||||||
if (dir == NULL)
|
if (_request.isDir(tmp) == 0)
|
||||||
{
|
|
||||||
_code = 404;
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
for (dirEnt = readdir(dir); !end && dirEnt; dirEnt = readdir(dir))
|
|
||||||
{
|
|
||||||
tmp = dirEnt->d_name;
|
|
||||||
if (tmp == _location->directoryFile)
|
|
||||||
{
|
{
|
||||||
|
if (_location->directoryFile.empty())
|
||||||
ret = tmp;
|
ret = tmp;
|
||||||
end = true;
|
else
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!end)
|
|
||||||
{
|
{
|
||||||
ret = _location->root;
|
ret = tmp + _location->directoryFile;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ret = tmp;
|
||||||
|
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +217,7 @@ void Response::generateBody(void)
|
|||||||
else
|
else
|
||||||
_code = 403;
|
_code = 403;
|
||||||
}
|
}
|
||||||
else if (!_request.badCode(_code) && _request.isFile(_request.getFullUri()) == 0)
|
else if (!_request.badCode(_code) && _request.isFile(_fullURI) == 0)
|
||||||
OpenResponseFile(_fullURI.c_str());
|
OpenResponseFile(_fullURI.c_str());
|
||||||
else if (_request.isFile(_fullURI) == -1)
|
else if (_request.isFile(_fullURI) == -1)
|
||||||
_code = 404;
|
_code = 404;
|
||||||
@@ -291,9 +284,9 @@ void Response::generate2(void)
|
|||||||
_hostPort.ip = _config->getHost();
|
_hostPort.ip = _config->getHost();
|
||||||
_hostPort.port = _config->getPort();
|
_hostPort.port = _config->getPort();
|
||||||
_fullURI = getFullURI();
|
_fullURI = getFullURI();
|
||||||
DBOUT << "fullURI " << _fullURI << ENDL;
|
|
||||||
_method = _request.getMethod();
|
_method = _request.getMethod();
|
||||||
|
|
||||||
|
DBOUT << "fullURI " << _fullURI << ENDL;
|
||||||
DBOUT << RED << "code is " << _code << ENDL;
|
DBOUT << RED << "code is " << _code << ENDL;
|
||||||
|
|
||||||
if (_request.badCode(_code) || !allowedMethod(_method))
|
if (_request.badCode(_code) || !allowedMethod(_method))
|
||||||
|
|||||||
Reference in New Issue
Block a user