Http-Server is a low-level C++ HTTP/1.1 server library. It exposes a small API under the http namespace for request parsing, response generation, connection management, and request and response body handling.
- Accepts HTTP/1.1 requests.
- Parses request lines, headers, and request bodies.
- Builds responses with headers and body data.
- Manages connections and request handling in an event-driven loop.
- It is not a routing framework.
- It does not provide middleware, templates, or session management.
- It does not hide HTTP details from the caller.
| Setting | Default |
|---|---|
| Port | 8080 |
| Pending connections | 128 |
| Concurrent connections | 128 |
| Idle timeout | 60 seconds |
| Logging | Disabled |
- Request line limit: 8 KB.
- Header block limit: 8 KB.
- Read buffer size: 8 KB.
- Response version is fixed to HTTP/1.1.
HttpRequestis read-only from user code.HttpResponseis mutated by the request handler.- Request and response body handling is stateful; repeated reads continue from the current position.
- Moving a request or response must preserve stream state in the destination object.
- Treat request and response objects as single-threaded, per-request objects.
- Do not share stream objects across threads unless you own the synchronization.
- Logging is synchronized internally.
- Most protocol and stream failures are reported through exceptions.
- Invalid requests, malformed headers, and unsupported protocol states fail fast.
- Body-related errors are surfaced through library exceptions.
You can build the library using either CMake or the provided script.
cmake -S . -B build
cmake --build buildsh ./build.sh --helpcmake --install buildFor a custom install prefix:
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/your/custom/path
cmake --build build
cmake --install buildfind_package(http REQUIRED)
target_link_libraries(your_target_name PRIVATE http::http)#include "http/http.hpp"HttpServer: server entry point.HttpServerConfig: server settings.HttpRequest: incoming request view.HttpResponse: outgoing response object.
#include "http/http.hpp"
#include <iostream>
#include <string>
#include <vector>
int main()
{
try
{
http::HttpServerConfig config;
config.port = 8080;
http::HttpServer server(config, [](const http::HttpRequest &, http::HttpResponse &response) {
response.set_status_code(http::status_codes::OK);
response.set_reason_phrase("OK");
response.set_header("Content-Type", "text/plain");
std::string body = "Hello, World!";
response.set_body(std::vector<char>(body.begin(), body.end()));
});
server.start();
}
catch (const std::exception &e)
{
std::cerr << "Error: " << e.what() << std::endl;
}
return 0;
}- Public headers are in
include/http/. - The exported CMake target is
http::http. - The library uses platform-specific socket/event backends under the hood.