Support HTTP proxies in WebSocketClient (#2635)

WebSocketClient gets the proxy setters Client has: set_proxy(),
set_proxy_basic_auth(), set_proxy_bearer_token_auth(), set_no_proxy()
and, in SSL builds, set_proxy_digest_auth(). connect() opens a CONNECT
tunnel for ws:// as well as wss:// (RFC 6455 4.1) and sends the proxy
credentials on the CONNECT request only. A proxy that does not answer
200 is reported as Error::ProxyConnection, with its status and headers
in Result.
This commit is contained in:
Kim, Hyuk authored and GitHub committed 2026-10-18 09:24:59 -04:00
1 parent 7220bdb8b2
commit 94cf1b5c9a
5 files changed
+683 -221

No files matched your search

+14
View File
@@ -69,6 +69,20 @@ cli.set_no_proxy({"internal.corp", "10.0.0.0/8", ".dev.local"});
不正な書式のエントリは黙って捨てられます。`example.com:8080`のようなポート指定エントリはサポート外です(cpp-httplibの他のホストキーAPIもホスト名のみを扱う設計のため)。
## WebSocketでもプロキシを使う
`ws::WebSocketClient`にも同じプロキシ設定があります。
```cpp
httplib::ws::WebSocketClient cli("wss://ws.example.com/chat");
cli.set_proxy("proxy.internal", 8080);
cli.set_proxy_basic_auth("user", "password");
auto res = cli.connect();
```
`ws://`でも`wss://`でも、CONNECTメソッドでトンネルを張ってからWebSocketのハンドシェイクを行います。`set_no_proxy()`も同じように使えます。
## 環境変数からプロキシ設定を読み込む
cpp-httplib本体は`HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY`を読みません。`set_ca_cert_path()`と同じで、設定APIは常に明示的にしています。環境変数を反映させたい場合は、アプリ側で読んで`set_proxy()`や`set_no_proxy()`に渡してください。