feat: update server configuration and enhance file handling

- Increased client_max_body_size to 1000m in default.conf and location /post_body
- Added index.html for YoupiBanane with a welcome message
- Created empty other.pouic file
- Updated FileHandler to change error response from 404 to 403 for forbidden access
- Modified log output to include blue text for status messages
- Changed signal handling variable from stop_ to signum_ in Server class
- Increased MAX_EVENTS in Server run method from 10 to 1024
This commit is contained in:
whaffman 2025-10-28 15:02:55 +01:00
parent 0534d07948
commit 0ed0e15e70
7 changed files with 33 additions and 20 deletions

View File

@ -117,7 +117,7 @@ server {
listen 8083;
host 127.0.0.1;
server_name localhost;
client_max_body_size 1000m;
root ./htdocs/YoupiBanane/;
index index.html index2.htm;
@ -134,7 +134,7 @@ server {
location /post_body {
root ./htdocs/YoupiBanane/;
client_max_body_size 100;
client_max_body_size 1000m;
allowed_methods POST;
}

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YoupiBanane</title>
</head>
<body>
<h1>Welcome to YoupiBanane!</h1>
<p>This is the index page.</p>
</body>
</html>

View File

@ -39,11 +39,12 @@ void FileHandler::handleFile(const std::string &filepath) const
std::vector<char> fileData = FileUtils::readBinaryFile(filepath);
Log::debug("Serving file: " + filepath + " with MIME type: " + mimeType);
if (fileData.empty())
{
ErrorHandler::createErrorResponse(Http::StatusCode::NOT_FOUND, response_, config_);
return;
}
// TODO empty file should not return 404 i guess
// if (fileData.empty())
// {
// ErrorHandler::createErrorResponse(Http::StatusCode::NOT_FOUND, response_, config_);
// return;
// }
// TODO: annoying: For reading files, vector<char> is preferred, but for http data vector<uint8_t> is preferred
response_.setBody(std::vector<uint8_t>{fileData.begin(), fileData.end()});
response_.setStatus(Http::StatusCode::OK);
@ -62,7 +63,7 @@ void FileHandler::handleDirectory(const std::string &dirpath, ResourceType type)
});
if (first_matching == possible_indexes.end())
{
ErrorHandler::createErrorResponse(Http::StatusCode::FORBIDDEN, response_, config_);
ErrorHandler::createErrorResponse(Http::StatusCode::NOT_FOUND, response_, config_);
return;
}
handleFile(FileUtils::joinPath(dirpath, *first_matching));

View File

@ -196,9 +196,10 @@ void Log::status(const std::string &message)
_statusActive = true;
// Save cursor position, move to bottom, clear line, print status, restore cursor
std::cout << "\033[s" // Save cursor position
<< "\033[999;0H" // Move to bottom row
<< "\033[2K" // Clear entire line
std::cout << "\033[s" // Save cursor position
<< "\033[999;0H" // Move to bottom row
<< "\033[2K" // Clear entire line
<< "\033[34m" // Set text color to blue
<< "\033[7m" // Reverse video (inverted colors)
<< message << "\033[0m" // Reset formatting
<< "\033[u" // Restore cursor position

View File

@ -1,9 +1,8 @@
#include <webserv/server/Server.hpp>
#include <webserv/client/Client.hpp> // for Client
#include <webserv/config/ConfigManager.hpp> // for ConfigManager
#include <webserv/config/ServerConfig.hpp> // for ServerConfig
#include <webserv/log/Log.hpp> // for Log, LOCATION
#include <webserv/server/Server.hpp>
#include <webserv/socket/ASocket.hpp> // for ASocket
#include <webserv/socket/ClientSocket.hpp> // for ClientSocket
#include <webserv/socket/ServerSocket.hpp> // for ServerSocket
@ -27,7 +26,7 @@
#include <sys/socket.h> // for SOMAXCONN
#include <unistd.h> // for close
volatile sig_atomic_t Server::stop_ = 0;
volatile sig_atomic_t Server::signum_ = 0;
Server::Server(const ConfigManager &configManager) : epoll_fd_(epoll_create1(O_CLOEXEC)), configManager_(configManager)
{
@ -308,12 +307,12 @@ void Server::run()
{
Log::trace(LOCATION);
Log::info("Listening...");
const int MAX_EVENTS = 10;
const int MAX_EVENTS = 1024;
struct epoll_event events[MAX_EVENTS]; // NOLINT
while (stop_ == 0)
while (signum_ == 0)
{
std::string status = "Active connections: " + std::to_string(clients_.size());
Log::status(status);
Log::status(status);
pollSockets();
pollClients();
handleEpoll(events, MAX_EVENTS); // NOLINT (cppcoreguidelines-pro-bounds-pointer-arithmetic)
@ -323,9 +322,8 @@ void Server::run()
void Server::signalHandler(int signum)
{
if (signum == SIGINT)
{
stop_ = signum;
signum_ = signum;
}
}

View File

@ -46,7 +46,7 @@ class Server
private:
int epoll_fd_;
static volatile sig_atomic_t stop_;
static volatile sig_atomic_t signum_;
const ConfigManager &configManager_;
std::vector<std::unique_ptr<ServerSocket>> listeners_;
std::set<int> listener_fds_;