Merge branch 'hugo2'

+ changed the appropriate getters for client
+ moved the functions to parse the http message
  (first line, headers, and body)
  outside client, in parsing_http_message.cpp
+ resolved some of the throw problems
This commit is contained in:
hugogogo
2022-08-09 15:54:40 +02:00
24 changed files with 205391 additions and 214 deletions

View File

@@ -20,11 +20,11 @@ void Webserv::_request(Client *client)
if (ret == READ_CLOSE)
{
_close_client(client->fd);
_close_client(client->get_cl_fd());
}
else if (ret == READ_COMPLETE)
{
_epoll_update(client->fd, EPOLLOUT, EPOLL_CTL_MOD);
_epoll_update(client->get_cl_fd(), EPOLLOUT, EPOLL_CTL_MOD);
}
}
@@ -34,13 +34,13 @@ int Webserv::_read_request(Client *client) // Messy, Need refactoring
ssize_t ret;
std::cerr << "call recv()" << "\n" ;
ret = ::recv(client->fd, buf, BUFSIZE, 0);
std::cerr << "recv() on fd(" << client->fd << ") returned = " << ret << "\n" ;
ret = ::recv(client->get_cl_fd(), buf, BUFSIZE, 0);
std::cerr << "recv() on fd(" << client->get_cl_fd() << ") returned = " << ret << "\n" ;
if (ret == -1)
{
std::perror("err recv()");
std::cerr << "client ptr =" << client << "\n"; // DEBUG
std::cerr << "client.fd =" << client->fd << "\n"; // DEBUG
std::cerr << "client.fd =" << client->get_cl_fd() << "\n"; // DEBUG
return READ_CLOSE;
}
if (ret == 0)
@@ -60,14 +60,14 @@ int Webserv::_read_request(Client *client) // Messy, Need refactoring
if (client->status) // WIP, need to change client->parse_request() for status update
return READ_COMPLETE;
client->assigned_server = _determine_process_server(client);
client->assigned_location = _determine_location(*client->assigned_server, client->get_path());
if (client->get_version().compare(0, sizeof("HTTP/1") - 1, "HTTP/1") != 0)
client->assigned_location = _determine_location(*client->assigned_server, client->get_rq_abs_path());
if (client->get_rq_version().compare(0, sizeof("HTTP/1") - 1, "HTTP/1") != 0)
{ // TODO : move in Client parsing ?
client->status = 505;
return READ_COMPLETE;
}
if (!client->get_headers("Content-Length").empty()
&& ::atoi(client->get_headers("Content-Length").c_str()) > (int)client->assigned_server->client_body_limit)
if (!client->get_rq_headers("Content-Length").empty()
&& ::atoi(client->get_rq_headers("Content-Length").c_str()) > (int)client->assigned_server->client_body_limit)
{
client->status = 413;
return READ_COMPLETE;
@@ -87,7 +87,7 @@ int Webserv::_read_request(Client *client) // Messy, Need refactoring
client->status = 413;
return READ_COMPLETE;
}
if ((int)client->read_body_size >= ::atoi(client->get_headers("Content-Length").c_str()))
if ((int)client->read_body_size >= ::atoi(client->get_rq_headers("Content-Length").c_str()))
{
client->parse_request(); // reparse for the body
return READ_COMPLETE;
@@ -95,7 +95,7 @@ int Webserv::_read_request(Client *client) // Messy, Need refactoring
}
if (client->header_complete && client->get_headers("Content-Type").empty() && client->get_headers("Content-Length").empty() )
if (client->header_complete && client->get_rq_headers("Content-Type").empty() && client->get_rq_headers("Content-Length").empty() )
{
return READ_COMPLETE;
}