mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
add : upload dir
This commit is contained in:
@@ -217,11 +217,15 @@ std::string Response::getFullURI(void)
|
|||||||
int pos = 0;
|
int pos = 0;
|
||||||
pos = _request.getURI().rfind("/");
|
pos = _request.getURI().rfind("/");
|
||||||
tmp = _request.getURI().substr(pos);
|
tmp = _request.getURI().substr(pos);
|
||||||
|
if (!_location->uploadDir.empty())
|
||||||
|
_upload_dir = _location->uploadDir + tmp;
|
||||||
tmp = _location->root + tmp;
|
tmp = _location->root + tmp;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tmp = _request.getURI().substr(len);
|
tmp = _request.getURI().substr(len);
|
||||||
|
if (!_location->uploadDir.empty())
|
||||||
|
_upload_dir = _location->uploadDir + tmp;
|
||||||
tmp = _location->root + tmp;
|
tmp = _location->root + tmp;
|
||||||
}
|
}
|
||||||
if (_request.isDir(tmp) == 0)
|
if (_request.isDir(tmp) == 0)
|
||||||
@@ -235,9 +239,11 @@ std::string Response::getFullURI(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = tmp;
|
ret = tmp;
|
||||||
|
if (_upload_dir.empty())
|
||||||
|
_upload_dir = ret;
|
||||||
DBOUT << PINK << "location " << _location->location << ENDL;
|
DBOUT << PINK << "location " << _location->location << ENDL;
|
||||||
DBOUT << PINK << "fullURI " << ret << ENDL;
|
DBOUT << PINK << "fullURI " << ret << ENDL;
|
||||||
|
DBOUT << PINK << "upload dir " << _upload_dir << ENDL;
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,11 +280,11 @@ bool Response::allowedMethod(std::string &method)
|
|||||||
{
|
{
|
||||||
if (*it == method)
|
if (*it == method)
|
||||||
return (true);
|
return (true);
|
||||||
DBOUT << BLUE << *it << ENDL;
|
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
if (_location->cgi_pass.empty())
|
if (!_location->cgi_pass.empty() && (method == "GET" || method == "POST"))
|
||||||
_code = 405;
|
return (true);
|
||||||
|
_code = 405;
|
||||||
return (false);
|
return (false);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -337,7 +343,7 @@ void Response::generate2(serverListen &l)
|
|||||||
_code = (_request.getBody()->size() > (unsigned long)_maxBodySize) ? 413 : _code;
|
_code = (_request.getBody()->size() > (unsigned long)_maxBodySize) ? 413 : _code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_request.badCode(_code) || (!allowedMethod(_method) && _location->cgi_pass.empty()) || isRedirect())
|
if (_request.badCode(_code) || !allowedMethod(_method) || isRedirect())
|
||||||
{
|
{
|
||||||
invalidClient();
|
invalidClient();
|
||||||
return;
|
return;
|
||||||
@@ -435,16 +441,16 @@ void Response::methodPost(void)
|
|||||||
void Response::methodPut(void)
|
void Response::methodPut(void)
|
||||||
{
|
{
|
||||||
_code = 201;
|
_code = 201;
|
||||||
if (_request.isFile(_fullURI) == 0)
|
if (_request.isFile(_upload_dir) == 0)
|
||||||
_code = 204;
|
_code = 204;
|
||||||
std::ofstream file(_fullURI.c_str(), std::ios::out | std::ios::binary);
|
std::ofstream file(_upload_dir.c_str(), std::ios::out | std::ios::binary);
|
||||||
if (!file.is_open())
|
if (!file.is_open())
|
||||||
_code = 403;
|
_code = 403;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
file.write(_request.getBody()->data(), _request.getBody()->size());
|
file.write(_request.getBody()->data(), _request.getBody()->size());
|
||||||
|
file.close();
|
||||||
}
|
}
|
||||||
file.close();
|
|
||||||
setHeaderBlocks();
|
setHeaderBlocks();
|
||||||
generateHeader();
|
generateHeader();
|
||||||
DBOUT << GREEN << "PUT method called" << ENDL;
|
DBOUT << GREEN << "PUT method called" << ENDL;
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ private:
|
|||||||
std::string _locationSTR;
|
std::string _locationSTR;
|
||||||
std::string _contentLanguage;
|
std::string _contentLanguage;
|
||||||
std::string _transferEncoding;
|
std::string _transferEncoding;
|
||||||
|
std::string _upload_dir;
|
||||||
|
|
||||||
void setHeaderBlocks(void);
|
void setHeaderBlocks(void);
|
||||||
void setContentType(void);
|
void setContentType(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user