Add WebSocket TLS and timeout recipes to the Cookbook

T04 (mTLS) had grown a "WebSocketClient" subsection describing
wss:// client certificates, and c12/t02 were getting similar
WebSocketClient asides for timeouts and CA paths. The Cookbook's
own index already separates WebSocket into its own category
(W01-W04) from TLS/Security (T01-T05) and Client (C01-C19), so
burying WebSocketClient specifics inside those pages fought the
site's structure.

Move that content into two new recipes under the WebSocket
category instead:

- W05: wss:// TLS setup (set_ca_cert_path CA directory parity,
  PemMemory client certificate)
- W06: WebSocketClient's three timeouts, including the recently
  added chrono overloads

T04, T02, C12, and W01 now carry a single reference link to the
new pages instead of duplicated explanations, matching the site's
existing cross-link convention.

While rewriting T04's client-side section, noticed it documented
SSLClient's file-path constructor but not its PemMemory one, even
though the server-side section covered both forms for SSLServer.
Added the missing PemMemory example so both sides are symmetric.
This commit is contained in:
yhirose
2026-08-07 17:17:07 -04:00
parent 2dd44d0f52
commit 8f0ff32056
14 changed files with 224 additions and 20 deletions

View File

@@ -57,25 +57,21 @@ auto res = cli.Get("/");
`Client`ではなく`SSLClient`を直接使う点に注意してください。秘密鍵にパスワードがある場合は第5引数で渡せます。
## WebSocketクライアントの場合
`ws::WebSocketClient`にも同じ`PemMemory`構造体があり、`wss://`接続でクライアント証明書を使えます。
クライアント側にも同じ`PemMemory`構造体があり、メモリ上のPEMからクライアント証明書を設定できます。
```cpp
httplib::ws::WebSocketClient::PemMemory pem{};
httplib::SSLClient::PemMemory pem{};
pem.cert_pem = client_cert.data();
pem.cert_pem_len = client_cert.size();
pem.key_pem = client_key.data();
pem.key_pem_len = client_key.size();
httplib::ws::WebSocketClient ws("wss://api.example.com/ws", pem);
httplib::SSLClient cli("api.example.com", 443, pem);
if (ws.connect()) {
ws.send("hello");
}
auto res = cli.Get("/");
```
`ws://`非TLSのURLに`PemMemory`を渡した場合は黙って無視されます。ファイルパスから直接読み込むコンストラクタは用意されていないので、`SSLClient`と違いPEMをメモリ上に読み込んでから渡す必要があります
> WebSocketクライアント`wss://`でmTLSを使う場合は[W05. wss接続でTLSを設定する](../w05-websocket-tls)を参照してください
## ハンドラからクライアント情報を取得する