Skip to content

kingak4/Webserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

151 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by kikwasni, alraltse, korzecho

Webserv Preview

📌 Description

Webserv is a custom HTTP server written entirely in C++ 98 as part of the 42 curriculum.

The objective of this project is to build a fully functional, non-blocking web server from scratch, without using any external web server libraries. The server must handle multiple clients simultaneously using a single I/O multiplexing mechanism such as poll(), select(), epoll(), or kqueue().

The program is executed as: ./webserv [configuration_file]

This server is designed to:

  • Parse and apply a configuration file inspired by NGINX
  • Handle multiple ports and multiple server blocks
  • Serve static websites
  • Support file uploads
  • Implement at least the GET, POST, and DELETE HTTP methods
  • Execute CGI scripts (e.g. PHP or Python)
  • Provide accurate HTTP status codes
  • Return default error pages when necessary
  • Remain fully non-blocking at all times
  • Properly handle client disconnections
  • Manage multiple simultaneous connections through a single event loop

The architecture is event-driven and built around non-blocking sockets. All socket I/O operations are performed only after readiness is confirmed through a single multiplexing call. The server must never hang indefinitely and must remain resilient under stress conditions.

Special attention is given to:

  • Correct HTTP request parsing
  • Header validation
  • Chunked transfer decoding
  • CGI communication through environment variables
  • Proper file descriptor management
  • Memory safety and resource cleanup

The configuration file allows:

  • Defining interface and port pairs
  • Setting default error pages
  • Limiting client body size
  • Configuring routes (allowed methods, redirections, root directories)
  • Enabling/disabling directory listing
  • Defining default index files
  • Enabling file uploads
  • Configuring CGI execution based on file extension

This project demonstrates low-level network programming, event-driven architecture, protocol handling, and system-level resource management in C++ 98.


🛠️ Instructions

Compilation

The project is written in C++ 98. Use the provided Makefile to compile:

make

Available rules:

  • make clean – remove object files
  • make fclean – remove object and executable files
  • make re – recompile everything

Execution

./webserv [path_to_configuration_file]

If no configuration file is provided, the server will attempt to load default.conf from the project root.

Testing

  • Web Browser: http://localhost:8080 (or port defined in config)
  • Curl:
curl -v http://localhost:8080
  • Telnet: manually simulate raw HTTP requests

⚙️ Configuration File

The configuration file defines server behavior and is inspired by NGINX. It allows hosting multiple virtual servers and defining rules per route.

Configurable options:

  • Interfaces & Ports: define IP addresses and ports
  • Client Limits: client_max_body_size for uploads
  • Error Handling: custom HTML pages for HTTP errors (404, 500, etc.)
  • Location Blocks:
    • Allowed HTTP methods
    • Root & index files
    • Autoindex (directory listing)
    • HTTP redirects (301/302)
    • CGI script execution based on file extension
    • Upload directory

📚 Resources

Documentation & Articles

Video Tutorials

About

This project consists of building a custom HTTP server in C++98. Its goal is to understand how communication between a web browser and a server works — from receiving and parsing requests to generating correct HTTP responses.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors