Skip to content

Commit 4145d22

Browse files
committed
feat: cpphttp - zero-dependency HTTP/1.1 server in C++17
0 parents  commit 4145d22

18 files changed

Lines changed: 1494 additions & 0 deletions

‎.github/workflows/ci.yml‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
name: ${{ matrix.os }} / ${{ matrix.build_type }}
12+
runs-on: ${{ matrix.os }}
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-22.04, ubuntu-20.04, macos-13]
18+
build_type: [Debug, Release]
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Configure CMake
25+
run: |
26+
cmake -B build \
27+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
28+
-DBUILD_EXAMPLES=ON
29+
30+
- name: Build
31+
run: cmake --build build --config ${{ matrix.build_type }} --parallel
32+
33+
- name: Smoke test (Linux only)
34+
if: runner.os == 'Linux'
35+
run: |
36+
./build/hello_world &
37+
SERVER_PID=$!
38+
sleep 1
39+
STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/api/health)
40+
kill $SERVER_PID
41+
[ "$STATUS" = "200" ] && echo "✓ Health check passed" || (echo "✗ Expected 200, got $STATUS" && exit 1)

‎.gitignore‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
build/
2+
.cache/
3+
*.o
4+
*.a
5+
*.so
6+
*.dylib
7+
CMakeCache.txt
8+
CMakeFiles/
9+
cmake_install.cmake
10+
Makefile
11+
compile_commands.json
12+
.DS_Store
13+
.vscode/
14+
.idea/
15+
*.swp

‎CMakeLists.txt‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(cpphttp VERSION 1.0.0 LANGUAGES CXX)
3+
4+
# ── C++17 ─────────────────────────────────────────────────────────────────────
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
9+
# ── Compiler warnings ─────────────────────────────────────────────────────────
10+
if(MSVC)
11+
add_compile_options(/W4 /WX)
12+
else()
13+
add_compile_options(-Wall -Wextra -Wpedantic -Wshadow -Wno-unused-parameter)
14+
endif()
15+
16+
# ── Library ───────────────────────────────────────────────────────────────────
17+
add_library(cpphttp
18+
src/server.cpp
19+
src/request.cpp
20+
src/response.cpp
21+
src/router.cpp
22+
src/logger.cpp
23+
)
24+
25+
target_include_directories(cpphttp PUBLIC
26+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
27+
$<INSTALL_INTERFACE:include>
28+
)
29+
30+
# pthreads for std::thread
31+
find_package(Threads REQUIRED)
32+
target_link_libraries(cpphttp PUBLIC Threads::Threads)
33+
34+
# ── Examples ──────────────────────────────────────────────────────────────────
35+
option(BUILD_EXAMPLES "Build example binaries" ON)
36+
37+
if(BUILD_EXAMPLES)
38+
add_executable(hello_world examples/hello_world.cpp)
39+
target_link_libraries(hello_world PRIVATE cpphttp)
40+
41+
add_executable(todo_api examples/todo_api.cpp)
42+
target_link_libraries(todo_api PRIVATE cpphttp)
43+
endif()
44+
45+
# ── Tests (optional) ──────────────────────────────────────────────────────────
46+
option(BUILD_TESTS "Build tests" OFF)
47+
48+
if(BUILD_TESTS)
49+
enable_testing()
50+
add_subdirectory(tests)
51+
endif()
52+
53+
# ── Install ───────────────────────────────────────────────────────────────────
54+
install(TARGETS cpphttp EXPORT cpphttpTargets)
55+
install(DIRECTORY include/ DESTINATION include)
56+
install(EXPORT cpphttpTargets
57+
FILE cpphttpTargets.cmake
58+
NAMESPACE cpphttp::
59+
DESTINATION lib/cmake/cpphttp
60+
)

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)