{"id":48037689,"url":"https://github.com/martavoi/cpp-http-srv","last_synced_at":"2026-04-04T14:00:21.840Z","repository":{"id":318781547,"uuid":"1076506575","full_name":"martavoi/cpp-http-srv","owner":"martavoi","description":"A low-level HTTP web server implementation using Boost.Asio and Boost.Beast, demonstrating modern C++23 features and asynchronous I/O patterns.","archived":false,"fork":false,"pushed_at":"2025-10-15T01:20:54.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-15T08:22:58.655Z","etag":null,"topics":["boost-asio","boost-beast","cpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/martavoi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-15T00:49:44.000Z","updated_at":"2025-10-15T01:21:59.000Z","dependencies_parsed_at":"2025-10-15T19:25:01.297Z","dependency_job_id":"5aab5268-c38c-4820-a094-770ea09e87a2","html_url":"https://github.com/martavoi/cpp-http-srv","commit_stats":null,"previous_names":["martavoi/cpp-http-srv"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/martavoi/cpp-http-srv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martavoi%2Fcpp-http-srv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martavoi%2Fcpp-http-srv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martavoi%2Fcpp-http-srv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martavoi%2Fcpp-http-srv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martavoi","download_url":"https://codeload.github.com/martavoi/cpp-http-srv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martavoi%2Fcpp-http-srv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31402277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-04T10:20:44.708Z","status":"ssl_error","status_checked_at":"2026-04-04T10:20:06.846Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["boost-asio","boost-beast","cpp"],"created_at":"2026-04-04T14:00:16.999Z","updated_at":"2026-04-04T14:00:21.787Z","avatar_url":"https://github.com/martavoi.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C++ HTTP Server\n\nA low-level HTTP web server implementation using Boost.Asio and Boost.Beast, demonstrating modern C++23 features and asynchronous I/O patterns.\n\n## Overview\n\nThis project showcases how to build a production-ready HTTP server from scratch using:\n- **Boost.Asio** for asynchronous networking and I/O\n- **Boost.Beast** for HTTP protocol handling\n- **C++20 Coroutines** for clean async code flow\n- **Multi-threading** for concurrent request handling\n\n## Features\n\n- ✅ Async I/O using Boost.Asio coroutines (`co_await`)\n- ✅ HTTP/1.1 with keep-alive support\n- ✅ Multi-threaded request processing\n- ✅ Graceful error handling\n- ✅ Docker support with multi-stage builds\n- ✅ Modern C++23 standards\n\n## Tech Stack\n\n- **Language**: C++23\n- **Compiler**: Clang 20+ (development) / GCC 13+ (Docker)\n- **Build System**: CMake 3.28+\n- **Libraries**:\n  - Boost 1.84+ (Asio, Beast, Log)\n  - libc++ (Clang) / libstdc++ (GCC)\n\n## Building\n\n### Prerequisites\n\n**Local Development:**\n- CMake 3.28+\n- Clang 20+ or GCC 13+\n- Boost 1.84+\n\n**Docker:**\n- Docker Engine\n\n### Local Build\n\n```bash\n# Configure with CMake\ncmake -S . -B build \\\n  -DCMAKE_CXX_COMPILER=clang++ \\\n  -DCMAKE_CXX_FLAGS=\"-stdlib=libc++\"\n\n# Build\ncmake --build build\n\n# Run\n./build/bin/cpp-http-srv\n```\n\nIf you have Boost installed in a custom location:\n```bash\ncmake -S . -B build \\\n  -DCMAKE_CXX_COMPILER=clang++ \\\n  -DCMAKE_CXX_FLAGS=\"-stdlib=libc++\" \\\n  -DBOOST_ROOT=/path/to/boost\n```\n\n### Docker Build\n\n```bash\n# Build image\ndocker build -t cpp-http-srv:latest .\n\n# Run container\ndocker run -p 8080:8080 cpp-http-srv:latest\n\n# Or use a different port if 8080 is reserved\ndocker run -p 8081:8080 cpp-http-srv:latest\n```\n\n## Usage\n\nThe server starts on port 8080 by default and accepts HTTP requests:\n\n```bash\n# Using curl\ncurl http://localhost:8080/\n\n# Using wget\nwget -O- http://localhost:8080/\n\n# Using browser\n# Navigate to http://localhost:8080/\n```\n\n**Response:**\n```\nHello, World!\n```\n\n## Architecture\n\n### Request Flow\n\n1. **Acceptor** listens on port 8080 for incoming connections\n2. Each connection spawns a **coroutine** that handles the socket lifecycle\n3. Requests are parsed by **Beast HTTP parser**\n4. Responses are constructed and sent back\n5. Connection supports **HTTP keep-alive** for multiple requests\n6. **4 worker threads** process requests concurrently\n\n### Key Components\n\n```\nio_context (event loop)\n    ├── acceptor coroutine (accepts connections)\n    └── connection coroutines (handle requests)\n            ├── async_read (parse HTTP request)\n            ├── process \u0026 build response\n            └── async_write (send HTTP response)\n```\n\n### Multi-threading\n\nThe server uses a thread pool pattern:\n- 4 threads run the `io_context` event loop\n- Work is distributed automatically by Boost.Asio\n- Each connection is handled independently\n- Thread-safe logging with Boost.Log\n\n## Implementation Details\n\n### HTTP Keep-Alive\n- Respects `Connection: keep-alive` header from clients\n- Reuses TCP connections for multiple requests\n- Reduces connection overhead\n\n### Buffer Management\n- Uses `flat_buffer` for efficient memory usage\n- Buffer is cleared between requests on persistent connections\n- Prevents memory leaks on long-lived connections\n\n### Error Handling\n- Graceful handling of client disconnections\n- Timeout on idle connections (30 seconds)\n- Non-blocking operations with proper error codes\n\n### Socket Options\n- `SO_REUSEADDR` enabled for quick server restarts\n- Binds to `0.0.0.0` for accessibility from all interfaces\n\n## Development\n\n### VS Code Setup\n\nThe repository includes VS Code configuration for:\n- **Build task**: Ctrl+Shift+B to compile\n- **IntelliSense**: Proper C++23 and Boost.Asio support\n- **Clang with libc++**: Matches development environment\n\n### Adding Features\n\nTo extend the server:\n1. Modify request handling in the connection coroutine (line 60-66 in `main.cpp`)\n2. Add routing logic based on `req.target()`\n3. Implement custom response handlers\n4. Add middleware for logging, auth, etc.\n\n## Performance Considerations\n\n- **Async I/O**: Non-blocking operations maximize throughput\n- **Thread pool**: Scales with CPU cores\n- **Zero-copy**: Beast minimizes memory allocations\n- **Connection pooling**: Keep-alive reduces TCP overhead\n\n## License\n\nMIT License - Feel free to use this as a learning resource or starting point for your own projects.\n\n## Acknowledgments\n\nBuilt with:\n- [Boost.Asio](https://www.boost.org/doc/libs/release/doc/html/boost_asio.html)\n- [Boost.Beast](https://www.boost.org/doc/libs/release/libs/beast/doc/html/index.html)\n- Modern C++ coroutines\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartavoi%2Fcpp-http-srv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartavoi%2Fcpp-http-srv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartavoi%2Fcpp-http-srv/lists"}