A lightweight, cross-platform HTTP/HTTPS client library for C++17 in an ultra-compact package.
- Zero Dependencies: Compiles with a single command without linking any external libraries.
- Cross-Platform: Works seamlessly on Linux, macOS, and Windows.
- HTTP/HTTPS Support: Built-in TLS support via embedded
BearSSLorMbed-TLS. - Memory Efficient: Chunked streaming keeps memory usage low and constant.
- Automatic Compression: Built-in Gzip and Deflate decompression via
miniz. - Smart Socket Pooling: Automatic connection reuse with intelligent cleanup.
- Production Ready: Timeout handling, connection management, and error recovery.
- HTTP Client: Full HTTP/1.1 implementation with chunked transfer encoding.
- TLS Support: Secure HTTPS connections via embedded
BearSSLorMbed-TLS. - Socket Pool: Automatic connection reuse with timestamp-based cleanup.
- Decompression: Automatic Gzip/Deflate handling via
miniz. - Headers Management: Complete HTTP headers parsing and manipulation.
BearSSL: Lightweight TLS implementation (no OpenSSL dependency).Mbed-TLS: TLS implementation.miniz: High-performance compression library.
- Streaming Architecture: Processes data in chunks (
16KB) - Constant Memory Usage: Memory footprint remains stable regardless of response size.
- Smart Buffering: Automatic buffer sizing based on Content-Length and compression.
- Socket Pool: Reuses connections for improved performance.
- Automatic Cleanup: Removes expired connections based on configurable timeout.
- Connection State: Tracks last usage timestamp for each socket.
- Graceful Handling: Detects and recovers from server-side disconnections.
First of all, you need to clone the repository.
git clone https://github.com/IsmaCortGtz/pocket-http.git
# If you want to use mbedtls you need to fetch submodules
git submodule update --init --recursiveThen, if you want to use HTTPS with BearSSL or MbedTLS you can privide your own certs.hpp file on include/pockethttp/Sockets/certs.hpp. The default one is created from the Mozilla CA Certificates.
# This command will create the certs.hpp file
# cryptography library is needed, install it with 'pip install cryptography'
python scripts/parse.py cacert.pemYou can build with CMake, I recommend you to use Ninja, but you can use Make if you want to,
# Create build directory
mkdir build
cd build
# Build
cmake .. -G Ninja -DUSE_POCKET_HTTP_MBEDTLS=ON
ninjaYou can see simple examples in examples/:
- basic_request.cpp
- download.cpp
- form_data.cpp
- form_urlencoded.cpp
- send_file.cpp
- send_json.cpp
- systemcerts.cpp
TODO
USE_POCKET_HTTP_BEARSSL(Default:OFF): Enable HTTPS support withBearSSL. Without this flag the TLSSocket wont be registered in SocketPool, so you can register your own implementation for HTTPS using aSocketWrapper.USE_POCKET_HTTP_MBEDTLS(Default:OFF): Enable HTTPS support withMbedTLS(recommended). Without this flag theMbedTLSSocketwont be registered in SocketPool, so you can register your own implementation for HTTPS using aSocketWrapper.USE_POCKET_HTTP_LOG(Default:OFF): Enable detailed information logging for debugging (onlystd::cout).USE_POCKET_HTTP_ERR(Default:OFF): Enable detailed error logging for debugging (onlystd::cerr).USE_POCKET_HTTP_MOZILLA_ROOT_CERTS(Default:OFF): Enable Mozilla Root Certificates for HTTPS.
Perfect for:
- Embedded Systems: Minimal memory footprint and zero dependencies
- Microservices: Lightweight HTTP client for service communication
- IoT Applications: Efficient HTTPS communication for resource-constrained devices
- Standalone Tools: No dependency hell, single-file distribution
- Cross-Platform Apps: Write once, compile anywhere
- Performance-Critical Applications: Streaming architecture prevents memory spikes
- Request Sending: Large payloads sent in 16KB chunks
- Response Receiving: Data processed as it arrives, never buffering entire response
- Memory Management: Constant memory usage regardless of payload size
- Compression: Automatic detection and decompression of Gzip/Deflate content
- Pool Creation: Maintains pool of reusable connections per host:port
- Usage Tracking: Each socket tagged with last activity timestamp
- Automatic Cleanup: Expired connections removed based on timeout
- Failure Recovery: Detects closed connections and creates new ones
- Memory: Constant ~64KB maximum usage regardless of response size
- Speed: Connection reuse eliminates handshake overhead
- Compression: Automatic decompression with minimal memory overhead
- TLS: Optimized BearSSL and
Mbed-TLSprovides fast HTTPS with small footprint
This is a focused, production-ready library. Contributions should maintain the zero-dependency philosophy and cross-platform compatibility.
- pocket-http: MIT. Copyright (c) 2025 Ismael CortΓ©s GutiΓ©rrez.
- miniz: MIT from richgel999/miniz. Copyright 2013-2014 RAD Game Tools and Valve Software. Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC.
- bearssl: MIT from bearssl.org. Copyright (c) 2016 Thomas Pornin pornin@bolet.org.
- base64: Base64 encoder/decoder library: MIT from tobiaslocker/base64. Copyright (c) 2019 Tobias Locker.
- mbedTLS: Apache-2.0 or GPL-2.0-or-later from Mbed-TLS/mbedtls. (Using Apache-2.0)
pocket-http - When you need HTTP/HTTPS that just works, everywhere, with zero hassle.