-1
Daily
16,985
stars
2,775
forks
193
watchers
1,002
prs
1,634
issues
190
releases
README
cpp-httplib
A C++11 single-file header-only cross platform HTTP/HTTPS library.
It's extremely easy to set up. Just include the httplib.h file in your code!
Learn more in the official documentation (built with docs-gen).
[!IMPORTANT]
This library uses 'blocking' socket I/O. If you are looking for a library with 'non-blocking' socket I/O, this is not the one that you want. Only HTTP/1.1 is supported — HTTP/2 and HTTP/3 are not implemented.
[!WARNING]
32-bit platforms are NOT supported. Use at your own risk. The library may compile on 32-bit targets, but no security review has been conducted for 32-bit environments. Integer truncation and other 32-bit-specific issues may exist. Security reports that only affect 32-bit platforms will be closed without action. The maintainer does not have access to 32-bit environments for testing or fixing issues. CI includes basic compile checks only, not functional or security testing.
Main Features
- HTTP Server/Client
- SSL/TLS support (OpenSSL, MbedTLS, wolfSSL)
- Stream API
- Server-Sent Events
- WebSocket
Simple examples
Server
c++
define CPPHTTPLIB_OPENSSL_SUPPORT
include "path/to/httplib.h"
// HTTP
httplib::Server svr;
// HTTPS
httplib::SSLServer svr("./cert.pem", "./key.pem");
svr.Get("/hi", {
res.set_content("Hello World!", "text/plain");
});
svr.listen("0.0.0.0", 8080);
Client
c++
define CPPHTTPLIB_OPENSSL_SUPPORT
include "path/to/httplib.h"
// HTTP
httplib::Client cli("http://yhirose.github.io");
// HTTPS
httplib::Client cli("https://yhirose.github.io");
if (auto res = cli.Get("/hi")) {
res-status;
res-body;
}
SSL/TLS Support
cpp-httplib supports multiple TLS backends through an abstraction layer:
| Backend | Define | Libraries | Notes |
| :------ | :----- | :-------- | :---- |
| OpenSSL | CPPHTTPLIB_OPENSSL_SUPPORT | libssl, libcrypto | 3.0 or later required |
| Mbed TLS | CPPHTTPLIB_MBEDTLS_SUPPORT | libmbedtls, libmbedx509, libmbedcrypto | 2.x, 3.x, and 4.x supported (auto-detected); 4.x renames libmbedcrypto to libtfpsacrypto |
| wolfSSL | CPPHTTPLIB_WOLFSSL_SUPPORT | libwolfssl | 5.x supported; must build with --enable-opensslall |
[!NOTE]
wolfSSL limitation: get_ca_certs() and get_ca_names() only reflect CA certificates loaded via load_ca_cert_store() or set_ca_cert_store(). Certificates loaded through set_ca_cert_path() or system certificates (load_system_certs) are not enumerable.
A wolfSSL server that verifies client certificates does not resume TLS sessions: wolfSSL shares its session cache between contexts, so a resumed session could carry a certificate checked against another server's client CA.
[!NOTE]
BoringSSL (best-effort): BoringSSL builds under CPPHTTPLIB_OPENSSL_SUPPORT and is exercised by CI against current upstream. Because BoringSSL does not guarantee API stability, support is best-effort — breakage may occasionally land. One known difference vs OpenSSL: BoringSSL's public headers require C++14 or later, so consumers must compile accorTop issues
Latest release
v0.66.0 v0.66.0 2026-11-10What's Changed Bug fixes - Client: a redirect now stays on the unix socket when the client uses set_address_family(AF_UNIX) (2658). An absolute Location used to have its host taken as a socket path, so the redirect failed or went to the wrong socket. Only localhost (the Host this client sends) counts as the same host, so a redirect to any other host still goes through the cross-host client and drops Authorization and Cookie. A host mapped with set_direct_hostname_addr_map keeps its mapping, and an https Location runs TLS over the socket with the Location's host. - Server: when creating a dyn