mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 13:27:59 +03:00
fix: leak in response class
This commit is contained in:
@@ -24,9 +24,9 @@ std::string Response::getHeader(void)
|
||||
{
|
||||
return (*_header);
|
||||
}
|
||||
std::string Response::getBody(void)
|
||||
std::string *Response::getBody(void)
|
||||
{
|
||||
return (*_body);
|
||||
return (_body);
|
||||
}
|
||||
|
||||
void Response::setData(Request request, ServerConfig *config)
|
||||
@@ -36,12 +36,21 @@ void Response::setData(Request request, ServerConfig *config)
|
||||
_config = config;
|
||||
}
|
||||
|
||||
void Response::setData(Request &request, ServerConfig *config, location *loc)
|
||||
void Response::setData(Request &request, ServerConfig *config, std::vector<location *> &loc)
|
||||
{
|
||||
_request = request;
|
||||
_code = request.getCode();
|
||||
_config = config;
|
||||
_location = loc;
|
||||
if (loc.empty())
|
||||
_code = 404;
|
||||
else
|
||||
{
|
||||
_location = loc[0];
|
||||
if (loc.size() == 2)
|
||||
_cgi_Pass = loc[1]->cgi_pass;
|
||||
else
|
||||
_cgi_Pass = _location->cgi_pass;
|
||||
}
|
||||
}
|
||||
|
||||
void Response::setHeaderBlocks(void)
|
||||
@@ -68,7 +77,10 @@ void Response::setContentType(void)
|
||||
|
||||
void Response::setContentLength()
|
||||
{
|
||||
_contentLength = _body->size();
|
||||
if (_body != NULL)
|
||||
_contentLength = _body->size();
|
||||
else
|
||||
_contentLength = 0;
|
||||
}
|
||||
|
||||
void Response::setServer(void)
|
||||
@@ -109,7 +121,7 @@ serverListen Response::getListen()
|
||||
|
||||
std::string Response::getCgiPass(void)
|
||||
{
|
||||
return (_location->cgi_pass);
|
||||
return (_cgi_Pass);
|
||||
}
|
||||
|
||||
ssize_t Response::getMaxBodySize(void)
|
||||
@@ -283,7 +295,7 @@ bool Response::allowedMethod(std::string &method)
|
||||
return (true);
|
||||
it++;
|
||||
}
|
||||
if (!_location->cgi_pass.empty() && (method == "GET" || method == "POST"))
|
||||
if (!_cgi_Pass.empty() && (method == "GET" || method == "POST"))
|
||||
return (true);
|
||||
_code = 405;
|
||||
return (false);
|
||||
@@ -330,7 +342,7 @@ void Response::generate2(serverListen &l)
|
||||
{
|
||||
_code = 404;
|
||||
}
|
||||
else
|
||||
else if (!_request.badCode(_code))
|
||||
{
|
||||
_listen = l;
|
||||
_errorPages = _config->getErrorPages();
|
||||
@@ -344,7 +356,6 @@ void Response::generate2(serverListen &l)
|
||||
if (_maxBodySize > 0 && _request.getBody() != NULL)
|
||||
_code = (_request.getBody()->size() > (unsigned long)_maxBodySize) ? 413 : _code;
|
||||
}
|
||||
|
||||
if (_request.badCode(_code) || !allowedMethod(_method) || isRedirect())
|
||||
{
|
||||
invalidClient();
|
||||
@@ -389,7 +400,7 @@ void Response::invalidClient(void)
|
||||
void Response::methodGet(void)
|
||||
{
|
||||
_body = new std::string;
|
||||
if (!_location->cgi_pass.empty())
|
||||
if (!_cgi_Pass.empty())
|
||||
{
|
||||
CgiHandle cgi(_request, *this);
|
||||
|
||||
@@ -416,7 +427,7 @@ void Response::methodGet(void)
|
||||
}
|
||||
void Response::methodPost(void)
|
||||
{
|
||||
if (!_location->cgi_pass.empty())
|
||||
if (!_cgi_Pass.empty())
|
||||
{
|
||||
_body = new std::string;
|
||||
CgiHandle cgi(_request, *this);
|
||||
@@ -565,5 +576,5 @@ std::string Response::getErrorPage(int code)
|
||||
|
||||
Response::~Response()
|
||||
{
|
||||
delete _location;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user