mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-19 11:19:36 +00:00
Bring the READMEs and the docs pages (en and ja) in line with the current header: - Fix the client sample that does not compile, the Transfer-Encoding statement for default headers, the verifier callback comment, the thread pool spawn rule, the sanitize_filename description, and the inverted Accept-Encoding sentence. - Describe recent behaviour: TLS errors behind Read/Write failures, Host validation, Connection: close for a body without length, content_reader rules, refused CONNECT, WebSocketClient proxies, CPPHTTPLIB_INTERIM_RESPONSE_MAX_COUNT, the SSE event size limit, and the payload limit of the Stream API. - Complete the API references of WebSocket, WebSocketClient and the stream:: helpers, and the SSE reconnect rules. - Fix cookbook pages: keychain loading on every backend, received Close status, a multipart sample that trusted the client's file name, an echo sample that sent binary as text, SNI, pre-request handler scope, stop() with WebSocket handlers, and the thread pool notes. - Restore the mutex in the LLM app's Chapter 5 code.
2.6 KiB
2.6 KiB
title, order, status
| title | order | status |
|---|---|---|
| T01. OpenSSL・mbedTLS・wolfSSLの選択指針 | 43 | draft |
cpp-httplibはTLSの実装を自前では持たず、3つのバックエンドの中から1つを選んで使います。ビルド時に有効にするマクロで切り替えます。
| バックエンド | マクロ | 特徴 |
|---|---|---|
| OpenSSL | CPPHTTPLIB_OPENSSL_SUPPORT |
最も広く使われている、機能が豊富 |
| mbedTLS | CPPHTTPLIB_MBEDTLS_SUPPORT |
軽量、組み込み向け |
| wolfSSL | CPPHTTPLIB_WOLFSSL_SUPPORT |
組み込み向け、商用サポートあり |
ビルド時の指定
httplib.hをインクルードする前に、使いたいバックエンドのマクロを定義します。
#define CPPHTTPLIB_OPENSSL_SUPPORT
#include <httplib.h>
リンク時にそのバックエンドのライブラリ(libssl、libcrypto、libmbedtls、libwolfsslなど)も必要です。
どれを選ぶか
迷ったらOpenSSL
機能が一番豊富で、情報も多いです。通常のサーバー用途やLinuxデスクトップ向けなら、まずこれで始めて問題ありません。
バイナリサイズを抑えたい、組み込みで使う
mbedTLSかwolfSSLが向いています。OpenSSLよりずっとコンパクトで、メモリ制約のあるデバイスでも動きます。
商用サポートが必要
wolfSSLには商用ライセンスとサポートがあります。製品に組み込むなら選択肢に入ります。
複数バックエンドを切り替えたい場合
ビルドバリアントとして切り分けて、同じソースをマクロ切替でコンパイルし直すのが一般的です。APIの違いは、cpp-httplib側でかなり吸収してくれますが、完全に同じ挙動ではないのでテストは必須です。
どのバックエンドでも使えるAPI
証明書の検証制御、SSLServerの立ち上げ、ピア証明書の取得などは、どのバックエンドでも同じAPIで呼べます。
Note: macOSでは、3つのどのバックエンドを使う場合でも、システムのキーチェーンからルート証明書を自動で読む設定(
CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN)がデフォルトで有効です。無効にしたい場合はCPPHTTPLIB_DISABLE_MACOSX_AUTOMATIC_ROOT_CERTIFICATESを定義してください。