{"id":23592878,"url":"https://github.com/asut00/webserv","last_synced_at":"2025-11-04T10:30:36.036Z","repository":{"id":268781842,"uuid":"881810625","full_name":"asut00/Webserv","owner":"asut00","description":"Custom HTTP server implemented in C++98, designed to handle client requests efficiently, parse HTTP messages, and serve static or dynamic content.","archived":false,"fork":false,"pushed_at":"2025-01-27T10:30:03.000Z","size":4252,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T11:42:01.159Z","etag":null,"topics":["cpp","http","http-server","server"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asut00.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-01T09:30:40.000Z","updated_at":"2025-01-27T10:30:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b5caa8d-9420-4f90-9b50-a3f60f5b5466","html_url":"https://github.com/asut00/Webserv","commit_stats":null,"previous_names":["asut00/webserv"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asut00%2FWebserv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asut00%2FWebserv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asut00%2FWebserv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asut00%2FWebserv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asut00","download_url":"https://codeload.github.com/asut00/Webserv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239432755,"owners_count":19637798,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","http","http-server","server"],"created_at":"2024-12-27T08:16:11.692Z","updated_at":"2025-11-04T10:30:35.993Z","avatar_url":"https://github.com/asut00.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webserv 🌐\n\n**Webserv** is a lightweight HTTP server built in C++. The challenge of this project was to implement core HTTP functionalities and create a fully functional web server, adhering to the HTTP/1.1 specification.\n\n![Enregistrement de l’écran 2024-12-18 à 22 29 25 (1)](https://github.com/user-attachments/assets/0c2f23c9-58b5-4f12-9500-8541e3dc2df6)\n\n\n## 📋 Table of Contents\n\n- [Introduction](#introduction)\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Configuration](#configuration)\n- [Testing](#testing)\n- [Technical Details](#technical-details)\n- [Author](#author)\n\n---\n\n## Introduction\n\nThis project was a deep dive into the inner workings of how data is shared and communicated over the internet we rely on every day. We developed a fully functional web server that handles HTTP requests, serves static files, executes CGI scripts, and efficiently manages multiple client connections simultaneously. Through this project, I gained valuable insights into the foundational principles of web servers and network communication.\n\nThis project emphasizes:\n- **Network programming**.\n- **Concurrency management**.\n- **Protocol compliance**.\n\n### Goals\n\n1. Understand and implement the HTTP/1.1 protocol.\n2. Handle multiple client connections using non-blocking I/O.\n3. Manage server configurations dynamically through a configuration file.\n\n---\n\n## Features\n\n- 🖥️ **Static File Serving**: Serve HTML, CSS, JS, or any static content.\n- 🧩 **CGI Support**: Run dynamic scripts (e.g., PHP, Python).\n- 📑 **Custom Configuration**: Define routes, error pages, and limits.\n- 📡 **Persistent Connections**: Handle `keep-alive` connections.\n- 🔄 **HTTP Methods**: Support for `GET`, `POST`, and `DELETE`.\n- 🔥 **Error Handling**: Customizable error pages for HTTP status codes.\n\n---\n\n## Installation\n\n1. **Clone the repository**:\n   ```bash\n   git clone https://github.com/asut00/webserv.git\n   cd webserv\n   ```\n\n2. **Compile the server**:\n   ```bash\n   make\n   ```\n\n   This will create the `webserv` executable.\n\n---\n\n## Usage\n\nTo start the server, provide a configuration file as an argument:\n\n```bash\n./webserv ./config_file/default.conf\n```\n\n### Logs:\n\nThe server logs incoming requests, responses, and errors to the console.\n\n---\n\n## Configuration\n\nThe server is configured through `.conf` files written in a custom format. Below is an example configuration:\n\n```plaintext\nserver {\n    listen 8080;\n    server_name localhost;\n\n    root /var/www/html;\n    index index.html;\n\n    error_page 404 /errors/404.html;\n\n    location /cgi-bin {\n        cgi_pass /usr/bin/python3;\n    }\n\n    client_max_body_size 10M;\n}\n```\n\n### Key Directives:\n\n- **`listen`**: Port number for the server to bind to.\n- **`server_name`**: Hostname for virtual hosting.\n- **`root`**: Root directory for serving files.\n- **`index`**: Default file to serve in a directory.\n- **`error_page`**: Custom error pages for specific HTTP status codes.\n- **`cgi_pass`**: Path to the CGI interpreter for dynamic scripts.\n- **`client_max_body_size`**: Maximum size for incoming requests.\n\n---\n\n## Testing\n\n### Basic Tests:\n\n1. Use `curl` to send HTTP requests:\n   ```bash\n   curl -X GET http://localhost:8081\n   curl -X POST -d \"data=example\" http://localhost:8081\n   ```\n\n2. Test the server with its static website:\n   - If you use the `./config_file/default.conf` config file, the `http://localhost:8081` URL will redirect you to a static website.\n   - This website allows any user to test the server's different features.\n\n3. Test error handling:\n   - Request a non-existent file to trigger a `404` error.\n\n### Load Testing:\n\nUse tools like [siege](https://github.com/JoeDog/siege), [ApacheBench](https://httpd.apache.org/docs/2.4/programs/ab.html) or [wrk](https://github.com/wg/wrk) to stress test the server:\n```bash\nsiege -b http://localhost:8081\n```\n\n```bash\nab -n 1000 -c 10 http://localhost:8081/\n```\n\n---\n\n## Technical Details\n\n### Core Components:\n\n1. **Socket Programming**:\n   - Utilizes `select()` for handling multiple clients.\n   - Manages incoming and outgoing connections efficiently.\n\n2. **Request Parsing**:\n   - Parses HTTP headers, methods, and body.\n   - Supports chunked encoding and multipart form data.\n\n3. **Response Generation**:\n   - Generates HTTP responses with appropriate headers and content.\n   - Includes support for `Content-Length` and `Content-Type`.\n\n4. **Concurrency**:\n   - Handles multiple clients simultaneously.\n   - Ensures data integrity and non-blocking operations.\n\n5. **CGI Integration**:\n   - Executes scripts in isolated processes.\n   - Sends the request body and environment variables to the script.\n\n---\n\n## Team\n\n- [@atwazar](https://github.com/atwazar)\n- [@asut00](https://github.com/asut00)  \n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasut00%2Fwebserv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasut00%2Fwebserv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasut00%2Fwebserv/lists"}