Library

cpp-httplib v0.64.0

Versionv0.64.0
Stars★ 16,952
Released2026-10-29

A C++ header-only HTTP/HTTPS server and client library

Release notes

## What's Changed

**Behavior changes**

Several changes below alter behavior that existing code may rely on:

- Server: an exception handler that sets no status now answers 500 (it used to send 200 or the status the throwing handler had set). `set_error_handler()` therefore runs for it too. On a WebSocket upgrade, an exception from the pre-routing handler, the pre-request handler or the sub-protocol selector now goes through the exception handler and is answered over HTTP, where it used to drop the connection.
- Server: `Range` is honored only on GET and HEAD. Other methods get the whole response.
- Server: a request whose `Transfer-Encoding` lists a coding besides a single `chunked` is answered with 501 and the connection is closed. A list whose final coding is not `chunked` still gets 400.
- Server: after answering a request whose body the handler left unread, the server skips at most `CPPHTTPLIB_UNREAD_PAYLOAD_MAX_LENGTH` (256KB by default, 0 for no limit) within the read timeout, and closes the connection otherwise.
- Server: a mount point serves no path with a segment ending in `.` or a space, on every platform. On Windows it also refuses a path containing `:`.
- Server: `set_file_extension_and_mimetype_mapping()` lowercases the extension and drops a leading `.` when it is set, so `".pdf"` and `"PDF"` both match `.pdf` and `.PDF` files.
- Server: chunked transfer coding counts the bytes around chunk data (size lines, extensions, CRLF) against a bound. Each chunk may spend 16 bytes plus twice its data, and the excess may build up to `CPPHTTPLIB_HEADER_MAX_LENGTH`. This applies to request bodies on the server and response bodies on the client.
- Server: invalid response header fields are dropped from `res.headers` before any header writer runs, so a writer set with `set_header_writer()` no longer sees them.
- Server: `set_trusted_proxies()` matches addresses as IP addresses, so an IPv4-mapped IPv6 peer matches the IPv4 address listed.
- Client: with `set_follow_location(true)`, only 301, 302, 303, 307 and 308 are followed.
- Client: a path given to a plain HTTP proxy must start with `/`. Otherwise the request fails with `Error::Write` before anything is written. This includes `OPTIONS *`.
- Client: after `set_*` changes a TLS setting (certificate or host name verification, a CA store, a verifier), a connection kept alive under the old settings is closed instead of reused.
- Client: a response stream honors `set_decompress(false)`.
- All TLS backends: a host name is matched against subjectAltName only (RFC 9525). A certificate that names its host only in the Common Name is rejected.
- `SSEClient::last_event_id()` returns `std::string` instead of `const std::string &`. Code that copies the result or binds it to a const reference still compiles.
- `set_hostname_addr_map()` is deprecated in favor of `set_direct_hostname_addr_map()`, which behaves the same.

**New features**

- `Server::set_compress()` turns off compression of handler responses, buffered or streamed. Compression stays on by default, and static file compression keeps its own setting. Turning it off over HTTPS avoids BREACH-style leaks.
- `set_tunnel_hostname_addr_map()` on `SSLClient`, `Client` and `WebSocketClient` sends a CONNECT tunnel to another address than the origin hostname. The Host header, the SNI and the certificate check inside the tunnel keep the original hostname. It corresponds to curl's `--connect-to`, and `set_direct_hostname_addr_map()` to `--resolve`.
- `WebSocketClient::set_basic_auth()` and `set_bearer_token_auth()` (#2652).

**Security-relevant fixes**

- Request parsing and message framing:
  - Read no body from a request without `Content-Length` or chunked `Transfer-Encoding` in builds without TLS too. They used to read what followed up to EOF on a connection about to close.
  - Bound the bytes around chunk data in chunked transfer coding, as described above.
  - Bound how much of an unread request body the server skips, as described abov…

Share this resource


Discovered 2026-10-30 Source GitHub Archive 2026-10 →