add: limit from body size

This commit is contained in:
Talyx
2022-02-10 22:13:38 +03:00
parent b178c3c8bf
commit e7373ce4e9
3 changed files with 16 additions and 7 deletions

View File

@@ -217,6 +217,10 @@ void Client::printClientInfo(void)
std::cout << GREEN << "request http versioin = " << _request.getVersion() << ZERO_C << std::endl;
std::cout << GREEN << "content-length = " << _request.getContentLength() << ZERO_C << std::endl;
std::cout << GREEN << "connection type = " << _request.getConnection() << ZERO_C << std::endl;
it = map.find("transfer-encoding");
if (it != map.end())
std::cout << GREEN << "transfer-encoding = " << it->second << ZERO_C << std::endl;
std::cout << BLUE << std::endl << "RESPONSE" << ZERO_C << std::endl << std::endl;
std::cout << GREEN << _response.getHeader() << ZERO_C << std::endl;

View File

@@ -196,7 +196,8 @@ void Request::splitData(std::string &data)
_head_ok = true;
parseHeader();
if (_contentLength == 0 && !_chunked)
if ((_contentLength == 0 && !_chunked) || (_method == "GET"
|| _method == "DELETE" || _method == "HEAD"))
_body_ok = true;
}
}

View File

@@ -197,7 +197,6 @@ std::string Response::getTime(void)
std::string Response::getFullURI(void)
{
std::string tmp;
std::string ret = "";
int len = _location->location.size();
@@ -210,8 +209,11 @@ 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)
{
@@ -320,11 +322,13 @@ void Response::generate2(serverListen &l)
_fullURI = getFullURI();
_method = _request.getMethod();
_maxBodySize = (_location->clientBodySize > 0) ? _location->clientBodySize : _config->getClientBodySize();
_code = (_request.getContentLength() > _maxBodySize) ? 413 : _code;
DBOUT << "max size" << _maxBodySize << ENDL;
DBOUT << "_location size" << _location->clientBodySize << ENDL;
DBOUT << "_config sieze" << _config->getClientBodySize() << ENDL;
DBOUT << "req size " << _request.getContentLength() << ENDL;
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;
}
DBOUT << "fullURI " << _fullURI << ENDL;