assign server and location to client in _read_request()

This commit is contained in:
LuckyLaszlo
2022-08-07 17:37:24 +02:00
parent 4ab099ee4d
commit 1ccf61bc68
5 changed files with 52 additions and 50 deletions

View File

@@ -2,8 +2,7 @@
#include "Webserv.hpp"
#define BUFSIZE 8192
#define MAX_HEADER_SIZE 42000
#define MAX_BODY_SIZE 500000 // test macro, replace with server config
#define MAX_HEADER_SIZE 42000 // arbitrary
void Webserv::_request(Client *client)
{
@@ -41,9 +40,10 @@ void Webserv::_read_request(Client *client)
{
client->header_complete = true;
client->parse_request(); // TODO : split function to avoid useless parsing ?
// TODO : determine server here for body size limit
client->assigned_server = _determine_process_server(client);
client->assigned_location = _determine_location(*client->assigned_server, client->get_path());
if (!client->get_headers("Content-Length").empty()
&& ::atoi(client->get_headers("Content-Length").c_str()) > MAX_BODY_SIZE)
&& ::atoi(client->get_headers("Content-Length").c_str()) > (int)client->assigned_server->client_body_limit)
{
client->status = 413;
_epoll_update(client->fd, EPOLLOUT, EPOLL_CTL_MOD);
@@ -60,7 +60,7 @@ void Webserv::_read_request(Client *client)
else if (client->header_complete)
{
client->read_body_size += ret;
if (client->read_body_size > MAX_BODY_SIZE)
if (client->read_body_size > client->assigned_server->client_body_limit)
{
client->status = 413;
_epoll_update(client->fd, EPOLLOUT, EPOLL_CTL_MOD);