mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-06-11 17:17:17 +00:00
docs: blend NO_PROXY env-var note into c16-proxy cookbook style
Match the granularity of the surrounding sections: imperative heading, inline paragraph instead of a heavyweight callout, and a simpler getenv snippet without the C++17 if-init.
This commit is contained in:
@@ -69,19 +69,19 @@ Hostname matching is case-insensitive and uses a dot-boundary rule, so an entry
|
||||
|
||||
Malformed entries are silently dropped. Port-specific entries such as `example.com:8080` are not supported (cpp-httplib's other host-keyed APIs are also keyed on hostname only).
|
||||
|
||||
## Reading proxy settings from the environment
|
||||
## Read proxy settings from the environment
|
||||
|
||||
cpp-httplib does not read `HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY` itself. The library's configuration API is explicit by design — `set_ca_cert_path()` is the same way. If you want that behavior, parse the variables in your application and feed them to `set_proxy()` and `set_no_proxy()`.
|
||||
cpp-httplib doesn't touch `HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY` on its own — the config API is always explicit, the same way `set_ca_cert_path()` is. If you'd like that behavior, read the variables in your application and feed them to `set_proxy()` and `set_no_proxy()`.
|
||||
|
||||
```cpp
|
||||
if (auto *v = std::getenv("no_proxy"); v && *v) {
|
||||
if (const char *v = std::getenv("no_proxy")) {
|
||||
std::vector<std::string> patterns;
|
||||
std::stringstream ss(v);
|
||||
for (std::string item; std::getline(ss, item, ',');) {
|
||||
if (!item.empty()) { patterns.push_back(std::move(item)); }
|
||||
if (!item.empty()) { patterns.push_back(item); }
|
||||
}
|
||||
cli.set_no_proxy(patterns);
|
||||
}
|
||||
```
|
||||
|
||||
> **Security Note:** If you also read `HTTP_PROXY` from the environment, prefer the lowercase `http_proxy` only. The uppercase form is poisoned in CGI/FastCGI environments by the `Proxy:` request header ([CVE-2016-5385 / "httpoxy"](https://httpoxy.org/)). `HTTPS_PROXY` and `NO_PROXY` are safe in either case because their names do not begin with `HTTP_`.
|
||||
If you also read `HTTP_PROXY` yourself, honor the lowercase `http_proxy` only. The uppercase form is poisoned in CGI/FastCGI environments by the `Proxy:` request header ([CVE-2016-5385 / "httpoxy"](https://httpoxy.org/)). `HTTPS_PROXY` and `NO_PROXY` are safe in either case because their names don't begin with `HTTP_`.
|
||||
|
||||
@@ -71,17 +71,17 @@ cli.set_no_proxy({"internal.corp", "10.0.0.0/8", "*.dev.local"});
|
||||
|
||||
## 環境変数からプロキシ設定を読み込む
|
||||
|
||||
cpp-httplib本体は`HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY`を読みません。設定APIを明示的に保つ方針で、`set_ca_cert_path()`なども同様です。必要なら、アプリ側で環境変数を読んで`set_proxy()`や`set_no_proxy()`に渡します。
|
||||
cpp-httplib本体は`HTTP_PROXY` / `HTTPS_PROXY` / `NO_PROXY`を読みません。`set_ca_cert_path()`と同じで、設定APIは常に明示的にしています。環境変数を反映させたい場合は、アプリ側で読んで`set_proxy()`や`set_no_proxy()`に渡してください。
|
||||
|
||||
```cpp
|
||||
if (auto *v = std::getenv("no_proxy"); v && *v) {
|
||||
if (const char *v = std::getenv("no_proxy")) {
|
||||
std::vector<std::string> patterns;
|
||||
std::stringstream ss(v);
|
||||
for (std::string item; std::getline(ss, item, ',');) {
|
||||
if (!item.empty()) { patterns.push_back(std::move(item)); }
|
||||
if (!item.empty()) { patterns.push_back(item); }
|
||||
}
|
||||
cli.set_no_proxy(patterns);
|
||||
}
|
||||
```
|
||||
|
||||
> **Security Note:** `HTTP_PROXY`をアプリ側で読む場合は、小文字の`http_proxy`だけを採用してください。大文字の方はCGI/FastCGI環境で`Proxy:`リクエストヘッダーから汚染される可能性があります([CVE-2016-5385 / "httpoxy"](https://httpoxy.org/))。`HTTPS_PROXY`や`NO_PROXY`は名前が`HTTP_`で始まらないので、どちらの大文字小文字でも安全です。
|
||||
`HTTP_PROXY`も自分で読むなら、小文字の`http_proxy`だけを採用してください。大文字の方はCGI/FastCGI環境で`Proxy:`リクエストヘッダーから汚染される可能性があります([CVE-2016-5385 / "httpoxy"](https://httpoxy.org/))。`HTTPS_PROXY`と`NO_PROXY`は名前が`HTTP_`で始まらないので、どちらの大文字小文字でも安全です。
|
||||
|
||||
Reference in New Issue
Block a user