Skip to content
lohhiicccPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

540 Commits

Folders and files

Repository files navigation

Webserv

A complete HTTP/1.1 server implemented in C++98 as part of the 42 school Webserv project.

Description

Webserv is an asynchronous non-blocking web server capable of handling multiple simultaneous clients through an event-driven architecture based on poll(). It implements the main features of a modern HTTP server including virtual hosting, CGI execution, and request handling.

Features

HTTP/1.1 Protocol

  • Supported methods: GET, POST, DELETE
  • Chunked transfer encoding
  • Timeout management: headers, inactivity, CGI
  • Complete HTTP status codes (2xx, 3xx, 4xx, 5xx)
  • Standard HTTP headers with automatic MIME type detection

HTTP Methods

GET

  • File serving with efficient streaming
  • AutoIndex: HTML generation of directory listings
  • Automatic MIME type detection

POST

  • File upload
  • Automatic unique filename generation
  • Write permission verification
  • Request body parsing with size limits

DELETE

  • File/directory deletion
  • Security checks for accessible paths

Common Gateway Interface (CGI)

  • Process forking with pipe communication
  • Standard CGI environment variables
  • Configurable execution timeout (4s default)
  • Complete CGI response header handling

Virtual Hosting

  • Multi-server: multiple servers in one instance
  • Selection by:
    • IP:Port binding
    • Hostname via Host header
  • Multiple locations with path matching
  • Hierarchical configuration with value inheritance

Technical Architecture

  • Event-driven architecture with poll() loop
  • Non-blocking I/O on all sockets
  • Multiplexing: up to 100 simultaneous clients
  • State management: requests and responses with state machine

Usage

Server Launch

# With default configuration
./webserv

# With custom configuration file
./webserv path/to/config.conf

Technical Architecture

Concurrency Model

The server uses an event-driven model with multiplexing:

  • Main loop with poll() (1000ms timeout)
  • Non-blocking I/O for all sockets
  • Simultaneous handling of up to 100 clients
  • Request/response states with state machine

Class Hierarchy

WebServer (Singleton)
├── VirtualHost[] (virtual servers)
│   ├── BindingInfo (IP:Port)
│   └── Location[] (locations)
└── Client[] (connected clients)
    ├── HttpRequest (parsing)
    ├── HttpResponse (generation)
    └── ARequestHandler (abstract handler)
        ├── MethodHandler (GET/POST/DELETE)
        └── CGIHandler (CGI execution)

Timeouts and Limits

Parameter Value Description
REQUEST_HEADERS_TIMEOUT 4s Header read timeout
INACTIVITY_TIMEOUT 7s Client inactivity timeout
CGI_EXECUTION_TIMEOUT 4s CGI execution timeout
MAX_CLIENTS 100 Maximum simultaneous clients
READ_BUFFER 8192 Read buffer size
WRITE_BUFFER 8192 Write buffer size

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages