From 82a9ef024de73ba46be0a0007ec421980a1b08cd Mon Sep 17 00:00:00 2001 From: sigoden Date: Sun, 5 May 2024 07:04:53 +0800 Subject: [PATCH] refactor: aware of lowercase https_proxy/all_proxy (#484) --- config.example.yaml | 4 ++-- src/client/common.rs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index ea9e2fa..8a4b227 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -38,8 +38,8 @@ clients: # extra_fields: # Set custom parameters, will merge with the body json # key: value # extra: - # proxy: socks5://127.0.0.1:1080 # Specify https/socks5 proxy server. ENV: HTTPS_PROXY/ALL_PROXY - # connect_timeout: 10 # Set a timeout in seconds for connect to server + # proxy: socks5://127.0.0.1:1080 # Set https/socks5 proxy. ENV: HTTPS_PROXY/https_proxy/ALL_PROXY/all_proxy + # connect_timeout: 10 # Set timeout in seconds for connect to api # See https://platform.openai.com/docs/quickstart - type: openai diff --git a/src/client/common.rs b/src/client/common.rs index e889bc8..fb0c38e 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -693,11 +693,14 @@ fn to_json(kind: &PromptKind, value: &str) -> Value { fn set_proxy(builder: ClientBuilder, proxy: &Option) -> Result { let proxy = if let Some(proxy) = proxy { - if proxy.is_empty() || proxy == "false" || proxy == "-" { + if proxy.is_empty() || proxy == "-" { return Ok(builder); } proxy.clone() - } else if let Ok(proxy) = env::var("HTTPS_PROXY").or_else(|_| env::var("ALL_PROXY")) { + } else if let Some(proxy) = ["HTTPS_PROXY", "https_proxy", "ALL_PROXY", "all_proxy"] + .into_iter() + .find_map(|v| env::var(v).ok()) + { proxy } else { return Ok(builder);