mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
change: location alg
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
name = "pohek1.org"
|
name = "pohek1.org"
|
||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
port = 8080
|
port = 8080
|
||||||
|
body_size_limit = 100000000
|
||||||
[[server.location]]
|
[[server.location]]
|
||||||
location = "/"
|
location = "/"
|
||||||
root = "www/tester/"
|
root = "www/tester/"
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ location *Config::getLocation(std::vector<location *> &arr, std::string &URI)
|
|||||||
std::string suffix1;
|
std::string suffix1;
|
||||||
std::vector<location *>::iterator it;
|
std::vector<location *>::iterator it;
|
||||||
std::vector<location *> step_1;
|
std::vector<location *> step_1;
|
||||||
|
std::vector<location *> step_2;
|
||||||
suffix = URI.substr(URI.rfind(".") + 1, URI.size() - URI.rfind("."));
|
suffix = URI.substr(URI.rfind(".") + 1, URI.size() - URI.rfind("."));
|
||||||
|
|
||||||
while (tryLen)
|
while (tryLen)
|
||||||
@@ -79,9 +80,8 @@ location *Config::getLocation(std::vector<location *> &arr, std::string &URI)
|
|||||||
it = step_1.begin();
|
it = step_1.begin();
|
||||||
tmp = *it;
|
tmp = *it;
|
||||||
if (tmp->location == URI || tmp->location.size() > 1)
|
if (tmp->location == URI || tmp->location.size() > 1)
|
||||||
return (tmp);
|
step_2.push_back(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
it = arr.begin();
|
it = arr.begin();
|
||||||
while (it != arr.end())
|
while (it != arr.end())
|
||||||
{
|
{
|
||||||
@@ -90,10 +90,23 @@ location *Config::getLocation(std::vector<location *> &arr, std::string &URI)
|
|||||||
{
|
{
|
||||||
suffix1 = tmp->location.substr(2);
|
suffix1 = tmp->location.substr(2);
|
||||||
if (suffix1 == suffix)
|
if (suffix1 == suffix)
|
||||||
return (tmp);
|
{
|
||||||
|
step_2.push_back(tmp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
it++;
|
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();
|
it = arr.begin();
|
||||||
while (it != arr.end())
|
while (it != arr.end())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ std::string Response::getCgiPass(void)
|
|||||||
return (_location->cgi_pass);
|
return (_location->cgi_pass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Response::getMaxBodySize(void)
|
||||||
|
{
|
||||||
|
return (_maxBodySize);
|
||||||
|
}
|
||||||
//-------------------------------------------------File---------------------------------------
|
//-------------------------------------------------File---------------------------------------
|
||||||
|
|
||||||
void Response::OpenResponseFile(const char *path)
|
void Response::OpenResponseFile(const char *path)
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
static std::string getReasonPhrase(int);
|
static std::string getReasonPhrase(int);
|
||||||
std::string getErrorPage(int code);
|
std::string getErrorPage(int code);
|
||||||
std::string getFullURI();
|
std::string getFullURI();
|
||||||
|
unsigned int getMaxBodySize(void);
|
||||||
bool isRedirect(void);
|
bool isRedirect(void);
|
||||||
bool allowedMethod(std::string &);
|
bool allowedMethod(std::string &);
|
||||||
void setData(Request, ServerConfig *);
|
void setData(Request, ServerConfig *);
|
||||||
|
|||||||
@@ -69,8 +69,6 @@ void Server::sendData(Client &client, int fd)
|
|||||||
else
|
else
|
||||||
send_len = BUFFSIZE;
|
send_len = BUFFSIZE;
|
||||||
|
|
||||||
/* DBOUT << YELLO << tmp << ENDL; */
|
|
||||||
/* DBOUT << GREEN << client.getCounter() << ENDL; */
|
|
||||||
DBOUT << "sent " << send_len << " to client " << fd << ENDL;
|
DBOUT << "sent " << send_len << " to client " << fd << ENDL;
|
||||||
|
|
||||||
|
|
||||||
@@ -91,8 +89,8 @@ void Server::readSocket(Client &client, int fd)
|
|||||||
// char buf[BUFFSIZE + 1];
|
// char buf[BUFFSIZE + 1];
|
||||||
std::string stringBUF(BUFFSIZE, 0);
|
std::string stringBUF(BUFFSIZE, 0);
|
||||||
|
|
||||||
DBOUT << TURQ << "IN readSocket" << ENDL;
|
// DBOUT << TURQ << "IN readSocket" << ENDL;
|
||||||
DBOUT << "client in readSocket "<< &client << ENDL;
|
// DBOUT << "client in readSocket "<< &client << ENDL;
|
||||||
bytes_read = recv(fd, &stringBUF[0], BUFFSIZE, 0);
|
bytes_read = recv(fd, &stringBUF[0], BUFFSIZE, 0);
|
||||||
if (bytes_read == 0)
|
if (bytes_read == 0)
|
||||||
{
|
{
|
||||||
@@ -119,16 +117,16 @@ void Server::readSocket(Client &client, int fd)
|
|||||||
client.allRead = true;
|
client.allRead = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
DBOUT << GREEN << "recvCounter " << client.getRecvCounter() << ENDL;
|
// DBOUT << GREEN << "recvCounter " << client.getRecvCounter() << ENDL;
|
||||||
DBOUT << GREEN << "contentLength " << client.getRequest().getContentLength() << ENDL;
|
// DBOUT << GREEN << "contentLength " << client.getRequest().getContentLength() << ENDL;
|
||||||
DBOUT << GREEN << "allRead " << client.allRead << ENDL;
|
// DBOUT << GREEN << "allRead " << client.allRead << ENDL;
|
||||||
|
// DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << ENDL;
|
||||||
DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << ENDL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server::delete_client(std::map<int,Client *> &client_map, int fd)
|
int Server::delete_client(std::map<int,Client *> &client_map, int fd)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
client_map[fd]->printClientInfo();
|
||||||
ret = epoll_ctl(_epoll_fd, EPOLL_CTL_DEL, fd, NULL);
|
ret = epoll_ctl(_epoll_fd, EPOLL_CTL_DEL, fd, NULL);
|
||||||
close(fd);
|
close(fd);
|
||||||
client_map[fd]->clear();
|
client_map[fd]->clear();
|
||||||
@@ -225,7 +223,7 @@ void Server::start(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
ready_num = epoll_wait(_epoll_fd, _events, MAX_CLIENT, 5000);
|
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)
|
if (ready_num < 0)
|
||||||
throw std::logic_error("epoll_ret");
|
throw std::logic_error("epoll_ret");
|
||||||
@@ -276,7 +274,7 @@ void Server::start(void)
|
|||||||
else if (events & EPOLLOUT)
|
else if (events & EPOLLOUT)
|
||||||
{
|
{
|
||||||
/* DBOUT << GREEN << "doing sendData" << ENDL; */
|
/* DBOUT << GREEN << "doing sendData" << ENDL; */
|
||||||
client_map[fd]->printClientInfo();
|
// client_map[fd]->printClientInfo();
|
||||||
sendData(*client_map[fd], fd);
|
sendData(*client_map[fd], fd);
|
||||||
if (client_map[fd]->allSended())
|
if (client_map[fd]->allSended())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user