Skip to content

Conversation

@a-chakkaf
Copy link
Collaborator

@a-chakkaf a-chakkaf commented May 13, 2025

Summary by CodeRabbit

  • New Features

    • Added support for multipart file uploads with chunked processing.
    • Introduced CGI script execution with environment variable handling.
    • Added comprehensive HTTP error responses including 403 Forbidden.
    • Implemented session and cookie management CGI examples.
    • Added interactive project landing page with file upload and deletion UI.
    • Added autoindex HTML generation for directory listings.
  • Improvements

    • Enhanced HTTP response handling with redirects, autoindex, and stricter request validation.
    • Expanded MIME type detection covering more file extensions.
    • Extended server configuration with client timeouts, upload directories, redirects, and CGI mappings.
    • Improved request parsing and environment conversion for CGI compatibility.
    • Added timeout handling for client connections.
  • Bug Fixes

    • Fixed file and folder deletion reliability.
    • Improved error handling for oversized payloads, invalid URLs, and unsupported methods.
  • Refactor

    • Modularized request, response, server, and client data management.
    • Cleaned up and reorganized includes and code structure.
    • Removed legacy and redundant source files and test scripts.
  • Style

    • Added modern, responsive CSS with animations and interactive UI elements for the web interface.
  • Documentation

    • Added static HTML error pages (403, 404, 405, 500) for user feedback.
    • Updated configuration files with consolidated and simplified server blocks.
  • Chores

    • Removed obsolete labs, test scripts, and debugging utilities.
    • Cleaned CI workflow by removing test execution step.

@coderabbitai
Copy link

coderabbitai bot commented May 13, 2025

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 251ca1c and 6d3169d.

📒 Files selected for processing (3)
  • Makefile (2 hunks)
  • main.cpp (2 hunks)
  • srcs/models/Cgi.cpp (1 hunks)
 ________________________________________________________
< Why so serious? Let's put a smile on that code's face. >
 --------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

Walkthrough

This update introduces a major refactor and expansion of a C++ web server project. It adds robust HTTP request/response handling, CGI execution, multipart file uploads, error page serving, and a modern, interactive web UI. Numerous new source and header files are created for modular server components, while legacy, experimental, and test files are removed. The configuration, build scripts, and static resources are overhauled to support new features and a streamlined deployment.

Changes

Files / Groups Change Summary
.gitignore Expanded with new ignore patterns for labs, test files, binaries, media, temp, and upload directories.
Makefile Added debug/sanitizer flags, expanded source lists, and ensured temp directory creation before build.
configs/config.conf Server configuration overhauled: ports, paths, timeouts, uploads, CGI, and error/route settings updated and simplified.
headers/Types.hpp New: Centralized includes, macros, enums (request types, progress, response codes), and typedefs for server-wide use.
headers/ClientData.hpp, srcs/utils/ClientData.cpp New: Defines a struct to track per-client connection state, request progress, uploads, and response pointers. Implements destructor for cleanup.
headers/Cgi.hpp, srcs/models/Cgi.cpp New: Class for CGI script execution, environment setup, interpreter selection, and output capture.
headers/HttpErrors.hpp, srcs/utils/httpResponseErrors.cpp New: Class with static methods for generating/sending HTTP error responses (400, 403, 405, 413, 414).
headers/MimeTypes.hpp, srcs/models/MimeTypes.cpp Extended: More MIME types, new method to get MIME type by file path.
headers/Response.hpp, srcs/models/Response.cpp Refactored: Class now handles HTTP response logic, file serving, redirects, error pages, CGI, autoindex, and resource cleanup.
headers/ResponseUtils.hpp, srcs/models/ResponseUtils.cpp New: Utility class for filesystem operations, error page retrieval, autoindex generation, and HTTP header construction.
headers/Request.hpp, srcs/models/Request.cpp Refactored: Parses HTTP requests, extracts method/path/headers/body, builds CGI environment, and provides accessors.
headers/Server.hpp, srcs/models/Server.cpp, srcs/utils/serverUtils.cpp Refactored: Server config parsing, new getters/setters for timeouts, roots, uploads, redirects, CGI; improved socket setup and validation.
headers/Webserv.hpp, srcs/models/Webserv.cpp Refactored: Event loop, client handling, poll integration, response preparation, timeouts, and resource management.
headers/WebservHandler.hpp, srcs/models/WebservHandler.cpp Refactored: Modularized request parsing, validation, multipart upload handling, POLLOUT enabling, and error responses.
headers/FtPars.hpp, srcs/parsing/helpers/FtPars.cpp Refactored: Parsing helpers for config, new functions for redirects/CGI, utility for current time in ms.
headers/header.hpp Refactored: New externs for global state, added multipart upload handler declaration.
headers/readConfig.hpp, srcs/parsing/config/readConfig.cpp Cleaned: Includes consolidated, server validation added post-config parsing.
srcs/models/Upload.cpp New: Implements multipart file upload handling, temp file management, and boundary parsing.
learning/cgi.cpp, learning/main.cpp, learning/index.html, learning/tst.py Deleted: Experimental CGI and HTTP server code, test HTML and Python script removed.
labs/*, labs/new/*, website01/*, run.sh, test/* Deleted: Legacy, experimental, and test code/scripts for earlier server prototypes and testing.
main.cpp Updated: Debug hooks removed, new global variables for server environment and error handling.
.github/workflows/ci.yml CI: Removed test execution step; now only builds.
var/www/html/errors/403.html, 404.html, 405.html, 500.html New: Static HTML error pages for standard HTTP errors.
var/www/html/main/index.html, style.css, script.js, page.html New: Modern, interactive landing page and file management UI with CSS/JS.
var/www/html/main/scripts/cookie_example.py, session_example.py New: Python CGI scripts demonstrating cookie and session management.
var/www/html/main/scripts/bash.sh Changed: From static HTML to Bash CGI script generating a welcome page.
var/www/html/magic/index.html, style.css New: "Magic" themed demo page with animated circles and custom styles.
var/www/html/simple/index.html Simplified: Minimal static HTML page.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Webserv
    participant WebservHandler
    participant Server
    participant ClientData
    participant Request
    participant Response
    participant ResponseUtils
    participant Cgi

    Client->>Webserv: Connects / Sends HTTP request
    Webserv->>WebservHandler: Reads and parses request
    WebservHandler->>ClientData: Updates connection state
    WebservHandler->>Request: Parses HTTP request
    WebservHandler->>Webserv: Signals request complete
    Webserv->>Response: Prepares HTTP response (GET/POST/DELETE)
    Response->>ResponseUtils: Checks file/dir, builds headers
    alt CGI required
        Response->>Cgi: Executes CGI script
        Cgi->>Response: Returns CGI output
    end
    Response->>ClientData: Stores response, sets progress READY
    Webserv->>Client: Sends response (headers, then body)
    alt Multipart upload
        WebservHandler->>ClientData: Handles multipart boundaries
        WebservHandler->>Upload.cpp: Writes file chunks, renames files
    end
    Webserv->>Client: Closes connection on completion or timeout
Loading

Poem

🐇

From tangled labs and scripts we leap,

A web of code, now strong and deep.

With CGI and uploads new,

Error pages, style, and magic too!

The server hops, responds, delights,

In CSS and bytes and starry nights.

— A rabbit’s code, now shining bright!

Tip

Migrating from UI to YAML configuration.

Use the @coderabbitai configuration command in a PR comment to get a dump of all your UI settings in YAML format. You can then edit this YAML file and upload it to the root of your repository to configure CodeRabbit programmatically.


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Join our Discord community for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@a-chakkaf a-chakkaf merged commit 6d3169d into main May 26, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants