Thanks to visit codestin.com
Credit goes to github.com

Skip to content

maitaad/webserver

Repository files navigation

Webserv

Description

Webserv is a simple HTTP server written in C++98 as part of a school project. It supports handling multiple client connections, serving static files, handling basic HTTP methods (GET, POST, DELETE), and running CGI scripts (like Python and PHP).

The project is designed to mimic the basic behavior of web servers such as NGINX, with a focus on understanding HTTP protocol and server-side networking.


Features

  • Support for multiple servers running on different ports.
  • Handles HTTP methods: GET, POST, and DELETE.
  • CGI execution (supports extensions like .php and .py).
  • File uploading support.
  • Autoindex (directory listing) feature.
  • Custom error pages handling.
  • Limits client body size.
  • Fully non-blocking I/O using poll().

Configuration Example

Example of server configuration:

server {
    listen 127.0.0.1;
    listen 127.0.0.1:8081;
    listen 127.0.0.1:8082;
    listen 127.0.0.1:8083;

    server_name localhost;

    location / {
        methods GET POST DELETE;
        root /Users/abayar/;
        autoindex ON;
        upload ./upload/;
        error_page 406 502 503 504 /Desktop/;
    }
    location /upload {
        methods GET POST DELETE;
        root /Users/abayar/Desktop/;
        cgi_path php;
    }

    client_max_body_size 44m;
}

server {
    listen 127.0.0.1;
    server_name localhost2;

    location / {
        methods GET POST;
        root /Users/abayar/Desktop/;
        index index.html;
        upload ./upload/;
        cgi_path py;
    }

    client_max_body_size 43m;
}

Installation and Usage

Build the project:

make

Run the server with a configuration file:

./webserv [config_file]

Example:

./webserv conf/webserv.conf

Makefile Commands

  • make — Compile the project.
  • make clean — Remove the compiled executable.
  • make fclean — Clean all generated files.
  • make re — Recompile the project.

Project Structure

  • parsing/ — Handles configuration file parsing and request parsing.
  • cgi/ — CGI handling (executing scripts).
  • methods/ — HTTP methods handling (GET, POST, DELETE).
  • server.cpp — Main server logic.
  • http_TcpServer.cpp — TCP server implementation.

Requirements

  • C++98
  • No external libraries
  • Compatible with browsers (tested with Chrome, Firefox, etc.)

Notes

  • This project is for educational purposes, focusing on understanding HTTP, socket programming, and server behavior.
  • The server is compatible with basic static websites and simple CGI-based web applications.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •