refactor: aware of lowercase https_proxy/all_proxy (#484)

This commit is contained in:
sigoden 2024-05-05 07:04:53 +08:00 committed by GitHub
parent 1ff0553c2f
commit 82a9ef024d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -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

View File

@ -693,11 +693,14 @@ fn to_json(kind: &PromptKind, value: &str) -> Value {
fn set_proxy(builder: ClientBuilder, proxy: &Option<String>) -> Result<ClientBuilder> {
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);