fix: linux tester

This commit is contained in:
Talyx
2022-02-10 00:36:34 +03:00
parent adbe832b98
commit 9b3b3bebca
4 changed files with 19 additions and 25 deletions

View File

@@ -9,11 +9,11 @@
autoindex = true autoindex = true
directory_file = "index.html" directory_file = "index.html"
[[server.location]] [[server.location]]
location = "/put_test/*" location = "/put_test"
root = "www/tester/" root = "www/tester/"
methods = ["PUT]"] methods = ["PUT"]
autoindex = true autoindex = true
upload_dir = "/www/tester/upload_here/" upload_dir = "www/tester/upload_here/"
[[server.location]] [[server.location]]
location = "*.bla" location = "*.bla"
cgi_pass = "~/.local/bin/cgi-test" cgi_pass = "~/.local/bin/cgi-test"
@@ -23,7 +23,7 @@
methods = ["POST"] methods = ["POST"]
body_size_limit = 100 body_size_limit = 100
[[server.location]] [[server.location]]
location = "/directory/" location = "/directory"
methods = ["GET"] methods = ["GET"]
root = "www/tester/YoupiBanane/" root = "www/tester/YoupiBanane/"
directory_file = "youpi.bad_extension" directory_file = "youpi.bad_extension"

View File

@@ -184,22 +184,15 @@ void Request::splitData(std::string &data)
str = std::string(data); str = std::string(data);
if (!_head_ok) if (!_head_ok)
{ {
pos = str.find("\r\n\r\n"); _head.insert(_head.end(), str.begin(), str.end());
/* if (pos == -1) */ pos = _head.find("\r\n\r\n");
/* { */ if (pos != -1)
/* _ret = 400; */
/* return; */
/* } */
DBOUT << RED << "pos is " << pos << ENDL;
if (pos == -1)
{ {
_head += str; std::string tmp;
} tmp = _head.substr(0, pos) + "\n";
else _headerSize = tmp.size() + 3;
{ str = _head.substr(_headerSize);
_head += str.substr(0, pos) + "\n"; _head = tmp;
_headerSize = _head.size() + 3;
data.erase(0, pos + 4);
_head_ok = true; _head_ok = true;
parseHeader(); parseHeader();
@@ -211,14 +204,13 @@ void Request::splitData(std::string &data)
return ; return ;
else if (_chunked) else if (_chunked)
{ {
_body.insert(_body.end(), data.begin(), data.end()); _body.insert(_body.end(), str.begin(), str.end());
if (checkEnd(_body, "0\r\n\r\n") == 0) if (checkEnd(_body, "0\r\n\r\n") == 0)
_body_ok = true; _body_ok = true;
} }
else if (!_body_ok) else if (_head_ok && !_body_ok)
{ {
_body.insert(_body.end(), str.begin(), str.end());
_body.insert(_body.end(), data.begin(), data.end());
if ((_received - _headerSize) == _contentLength) if ((_received - _headerSize) == _contentLength)
{ {
_body_ok = true; _body_ok = true;

View File

@@ -214,7 +214,7 @@ std::string Response::getFullURI(void)
ret = tmp; ret = tmp;
else else
{ {
ret = tmp + _location->directoryFile; ret = tmp + "/" + _location->directoryFile;
} }
} }
else else
@@ -256,8 +256,10 @@ bool Response::allowedMethod(std::string &method)
{ {
if (*it == method) if (*it == method)
return (true); return (true);
DBOUT << BLUE << *it << ENDL;
it++; it++;
} }
DBOUT << "location " << _location->location << ENDL;
_code = 405; _code = 405;
return (false); return (false);

View File

@@ -104,7 +104,7 @@ void Server::readSocket(Client &client, int fd)
/* else if (bytes_read == -1) */ /* else if (bytes_read == -1) */
/* throw std::logic_error("JOPA CLIENTU"); */ /* throw std::logic_error("JOPA CLIENTU"); */
// buf[bytes_read + 1] = '\0'; // buf[bytes_read + 1] = '\0';
DBOUT << stringBUF << ENDL; // DBOUT << stringBUF << ENDL;
stringBUF.erase(bytes_read, stringBUF.size()); stringBUF.erase(bytes_read, stringBUF.size());
/* DBOUT << "after erase" <<ENDL; */ /* DBOUT << "after erase" <<ENDL; */
/* DBOUT << stringBUF << ENDL; */ /* DBOUT << stringBUF << ENDL; */