diff options
| author | sigoden <sigoden@gmail.com> | 2023-03-12 08:31:06 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-12 08:31:06 +0800 |
| commit | 8fa2e2683bdb89aef5baf22957af1d86ed38aca7 (patch) | |
| tree | 3434c9c2610724a9507d5cca082f637b2f1d576a /src | |
| parent | 0ed0ad1fd26cccb9f41379e2f0f2c77fca43c608 (diff) | |
| download | aichat-8fa2e2683bdb89aef5baf22957af1d86ed38aca7.tar.gz | |
feat: support HTTPS_PROXY and ALL_PROXY (#68)
Diffstat (limited to 'src')
| -rw-r--r-- | src/client.rs | 3 | ||||
| -rw-r--r-- | src/config/mod.rs | 10 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/client.rs b/src/client.rs index 7fc2824..916a1ef 100644 --- a/src/client.rs +++ b/src/client.rs @@ -126,7 +126,8 @@ impl ChatGptClient { fn build_client(&self) -> Result<Client> { let mut builder = Client::builder(); if let Some(proxy) = self.config.read().proxy.as_ref() { - builder = builder.proxy(Proxy::all(proxy).with_context(|| "Invalid config.proxy")?); + builder = builder + .proxy(Proxy::all(proxy).with_context(|| format!("Invalid proxy `{proxy}`"))?); } let client = builder .connect_timeout(CONNECT_TIMEOUT) diff --git a/src/config/mod.rs b/src/config/mod.rs index b0cd6c0..a37140c 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -106,6 +106,7 @@ impl Config { bail!("api_key not set"); } config.merge_env_vars(); + config.maybe_proxy(); config.load_roles()?; Ok(config) @@ -430,6 +431,15 @@ impl Config { } } } + + fn maybe_proxy(&mut self) { + if self.proxy.is_some() { + return; + } + if let Ok(value) = env::var("HTTPS_PROXY").or_else(|_| env::var("ALL_PROXY")) { + self.proxy = Some(value); + } + } } fn create_config_file(config_path: &Path) -> Result<()> { |
