From cec4ae69e16b08dc02c9f187d47b06f440581693 Mon Sep 17 00:00:00 2001 From: Talyx Date: Sat, 12 Feb 2022 18:57:07 +0300 Subject: [PATCH] change: location alg --- config/tester.toml | 1 + src/Client/Config.cpp | 19 ++++++++++++++++--- src/Client/Response.cpp | 4 ++++ src/Client/Response.hpp | 2 +- src/Server/Server.cpp | 20 +++++++++----------- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/config/tester.toml b/config/tester.toml index ad00edc..9d2d763 100644 --- a/config/tester.toml +++ b/config/tester.toml @@ -2,6 +2,7 @@ name = "pohek1.org" host = "127.0.0.1" port = 8080 + body_size_limit = 100000000 [[server.location]] location = "/" root = "www/tester/" diff --git a/src/Client/Config.cpp b/src/Client/Config.cpp index 2ec7fe3..43f6d0f 100644 --- a/src/Client/Config.cpp +++ b/src/Client/Config.cpp @@ -57,6 +57,7 @@ location *Config::getLocation(std::vector &arr, std::string &URI) std::string suffix1; std::vector::iterator it; std::vector step_1; + std::vector step_2; suffix = URI.substr(URI.rfind(".") + 1, URI.size() - URI.rfind(".")); while (tryLen) @@ -79,9 +80,8 @@ location *Config::getLocation(std::vector &arr, std::string &URI) it = step_1.begin(); tmp = *it; if (tmp->location == URI || tmp->location.size() > 1) - return (tmp); + step_2.push_back(tmp); } - it = arr.begin(); while (it != arr.end()) { @@ -90,10 +90,23 @@ location *Config::getLocation(std::vector &arr, std::string &URI) { suffix1 = tmp->location.substr(2); if (suffix1 == suffix) - return (tmp); + { + step_2.push_back(tmp); + break; + } } it++; } + if (step_2.size() == 1) + return (step_2[0]); + else if (step_2.size() == 2) + { + if(!step_2[1]->cgi_pass.empty()) + { + step_2[0]->cgi_pass = step_2[1]->cgi_pass; + } + return (step_2[0]); + } it = arr.begin(); while (it != arr.end()) { diff --git a/src/Client/Response.cpp b/src/Client/Response.cpp index b2f1813..25f75fe 100644 --- a/src/Client/Response.cpp +++ b/src/Client/Response.cpp @@ -103,6 +103,10 @@ std::string Response::getCgiPass(void) return (_location->cgi_pass); } +unsigned int Response::getMaxBodySize(void) +{ + return (_maxBodySize); +} //-------------------------------------------------File--------------------------------------- void Response::OpenResponseFile(const char *path) diff --git a/src/Client/Response.hpp b/src/Client/Response.hpp index 3bd59df..3221795 100644 --- a/src/Client/Response.hpp +++ b/src/Client/Response.hpp @@ -67,7 +67,7 @@ public: static std::string getReasonPhrase(int); std::string getErrorPage(int code); std::string getFullURI(); - + unsigned int getMaxBodySize(void); bool isRedirect(void); bool allowedMethod(std::string &); void setData(Request, ServerConfig *); diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index 5c608a7..a173378 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -69,8 +69,6 @@ void Server::sendData(Client &client, int fd) else send_len = BUFFSIZE; - /* DBOUT << YELLO << tmp << ENDL; */ - /* DBOUT << GREEN << client.getCounter() << ENDL; */ DBOUT << "sent " << send_len << " to client " << fd << ENDL; @@ -91,8 +89,8 @@ void Server::readSocket(Client &client, int fd) // char buf[BUFFSIZE + 1]; std::string stringBUF(BUFFSIZE, 0); - DBOUT << TURQ << "IN readSocket" << ENDL; - DBOUT << "client in readSocket "<< &client << ENDL; + // DBOUT << TURQ << "IN readSocket" << ENDL; + // DBOUT << "client in readSocket "<< &client << ENDL; bytes_read = recv(fd, &stringBUF[0], BUFFSIZE, 0); if (bytes_read == 0) { @@ -119,16 +117,16 @@ void Server::readSocket(Client &client, int fd) client.allRead = true; } - DBOUT << GREEN << "recvCounter " << client.getRecvCounter() << ENDL; - DBOUT << GREEN << "contentLength " << client.getRequest().getContentLength() << ENDL; - DBOUT << GREEN << "allRead " << client.allRead << ENDL; - - DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << ENDL; + // DBOUT << GREEN << "recvCounter " << client.getRecvCounter() << ENDL; + // DBOUT << GREEN << "contentLength " << client.getRequest().getContentLength() << ENDL; + // DBOUT << GREEN << "allRead " << client.allRead << ENDL; + // DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << ENDL; } int Server::delete_client(std::map &client_map, int fd) { int ret; + client_map[fd]->printClientInfo(); ret = epoll_ctl(_epoll_fd, EPOLL_CTL_DEL, fd, NULL); close(fd); client_map[fd]->clear(); @@ -225,7 +223,7 @@ void Server::start(void) { ready_num = epoll_wait(_epoll_fd, _events, MAX_CLIENT, 5000); - DBOUT << TURQ << "ready_num " << ready_num << ENDL; + // DBOUT << TURQ << "ready_num " << ready_num << ENDL;F if (ready_num < 0) throw std::logic_error("epoll_ret"); @@ -276,7 +274,7 @@ void Server::start(void) 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()) {