Moved most request errors check in Client
+ bugfix of "Bad file descriptor" due to empty operator=() in Client + added a condition in _determine_location_COOP_FIX() + udpate memo.txt + need fix for index/autoindex (location "/list" dont work)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
|
||||
#include "Webserv.hpp"
|
||||
|
||||
#define BUFSIZE 8192
|
||||
#define MAX_HEADER_SIZE 42000 // arbitrary
|
||||
// Arbitrary values
|
||||
#define BUFSIZE 8192 // (8Ko)
|
||||
#define MAX_HEADER_SIZE 16384 // (16Ko)
|
||||
|
||||
enum read_return
|
||||
{
|
||||
@@ -54,28 +55,19 @@ int Webserv::_read_request(Client *client) // Messy, Need refactoring
|
||||
{
|
||||
if (client->raw_request.find(CRLF CRLF) != std::string::npos)
|
||||
{
|
||||
// std::cerr << "Raw_request :\n|||||||||||||||||||||||||||||\n " << client->raw_request << "\n|||||||||||||||||||||||||||||\n"; // DEBUG
|
||||
client->header_complete = true;
|
||||
client->parse_request(); // TODO : split function to avoid useless parsing ?
|
||||
if (client->status) // WIP, need to change client->parse_request() for status update
|
||||
client->parse_request(_servers);
|
||||
std::cerr << client->get_rq_method_str() << " " << client->get_rq_uri() << " " << client->get_rq_version() << "\n"; // DEBUG
|
||||
if (client->status)
|
||||
return READ_COMPLETE;
|
||||
client->assigned_server = _determine_process_server(client);
|
||||
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;
|
||||
|
||||
if (client->get_rq_headers("Content-Type").empty() && client->get_rq_headers("Content-Length").empty()) // No body case
|
||||
return READ_COMPLETE;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
else if (client->raw_request.size() > MAX_HEADER_SIZE)
|
||||
{
|
||||
client->status = 400;
|
||||
// 413 or 400 ? 413 seems common among http server, but don't fit perfectly.
|
||||
client->status = 413;
|
||||
return READ_COMPLETE;
|
||||
}
|
||||
}
|
||||
@@ -89,17 +81,10 @@ int Webserv::_read_request(Client *client) // Messy, Need refactoring
|
||||
}
|
||||
if ((int)client->read_body_size >= ::atoi(client->get_rq_headers("Content-Length").c_str()))
|
||||
{
|
||||
client->parse_request(); // reparse for the body
|
||||
client->parse_request_body();
|
||||
return READ_COMPLETE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (client->header_complete && client->get_rq_headers("Content-Type").empty() && client->get_rq_headers("Content-Length").empty() )
|
||||
{
|
||||
return READ_COMPLETE;
|
||||
}
|
||||
|
||||
return READ_IN_PROGRESS;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user