From f7783460e327bfe9e9032af634bfcdf75a20aaf8 Mon Sep 17 00:00:00 2001 From: 3lswear Date: Wed, 9 Feb 2022 22:58:43 +0300 Subject: [PATCH] feat: try to fix tester --- src/Client/Request.cpp | 29 ++++++++++++++++++++--------- src/Server/Server.cpp | 17 ++++++++++++----- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/Client/Request.cpp b/src/Client/Request.cpp index 06996f9..aedc783 100644 --- a/src/Client/Request.cpp +++ b/src/Client/Request.cpp @@ -185,18 +185,27 @@ void Request::splitData(std::string &data) if (!_head_ok) { pos = str.find("\r\n\r\n"); + /* if (pos == -1) */ + /* { */ + /* _ret = 400; */ + /* return; */ + /* } */ + DBOUT << RED << "pos is " << pos << ENDL; if (pos == -1) { - _ret = 400; - return; + _head += str; + } + else + { + _head += str.substr(0, pos) + "\n"; + _headerSize = _head.size() + 3; + data.erase(0, pos + 4); + _head_ok = true; + + parseHeader(); + if (_contentLength == 0 && !_chunked) + _body_ok = true; } - _head = str.substr(0, pos) + "\n"; - _headerSize = _head.size() + 3; - data.erase(0, pos + 4); - _head_ok = true; - parseHeader(); - if (_contentLength == 0 && !_chunked) - _body_ok = true; } if (badCode(_ret)) return ; @@ -336,6 +345,8 @@ bool Request::badCode(int code) bool Request::ok(void) { + DBOUT << "_head_ok " << _head_ok << ENDL; + DBOUT << "_body_ok " << _body_ok << ENDL; return (_head_ok && _body_ok); } diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index 75b1fc5..2ca1231 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -96,18 +96,25 @@ void Server::readSocket(Client &client, int fd) bytes_read = recv(fd, &stringBUF[0], BUFFSIZE, 0); if (bytes_read == 0) { + DBOUT << RED << "bytes_read = 0" << ENDL; client.allRead = true; + throw std::logic_error("JOPA CLIENTU"); return; } + /* else if (bytes_read == -1) */ + /* throw std::logic_error("JOPA CLIENTU"); */ // buf[bytes_read + 1] = '\0'; + DBOUT << stringBUF << ENDL; stringBUF.erase(bytes_read, stringBUF.size()); + /* DBOUT << "after erase" <isEmpty()) - delete_client(client_map, fd); + /* if (client_map[fd]->isEmpty()) */ + /* delete_client(client_map, fd); */ } else if (events & EPOLLOUT) { /* DBOUT << GREEN << "doing sendData" << ENDL; */ - /* client_map[fd].printClientInfo(); */ + client_map[fd]->printClientInfo(); sendData(*client_map[fd], fd); if (client_map[fd]->allSended()) {