mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-30 07:07:17 +02:00
Fix license activation and plugin requests ignoring proxy settings
Make yaak_api_client() read proxy settings from the database and apply them to the reqwest client. Also replace bare reqwest::Client::new() calls in license activate/deactivate with yaak_api_client() so they get proxy support (and consistent UA/headers/timeout). Fixes https://yaak.app/feedback/posts/cannot-activate-license Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
1127d7e3fa
commit
83f6f9786b
@@ -11,3 +11,5 @@ thiserror = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
regex = "1.11.0"
|
||||
yaak-common = { workspace = true }
|
||||
yaak-models = { workspace = true }
|
||||
log = { workspace = true }
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
use crate::error::Result;
|
||||
use reqwest::Client;
|
||||
use log::{debug, warn};
|
||||
use reqwest::{Client, Proxy};
|
||||
use std::time::Duration;
|
||||
use tauri::http::{HeaderMap, HeaderValue};
|
||||
use tauri::{AppHandle, Runtime};
|
||||
use tauri::{AppHandle, Manager, Runtime};
|
||||
use yaak_common::platform::{get_ua_arch, get_ua_platform};
|
||||
use yaak_models::models::{ProxySetting, ProxySettingAuth};
|
||||
use yaak_models::query_manager::QueryManager;
|
||||
|
||||
pub fn yaak_api_client<R: Runtime>(app_handle: &AppHandle<R>) -> Result<Client> {
|
||||
let platform = get_ua_platform();
|
||||
@@ -13,12 +16,58 @@ pub fn yaak_api_client<R: Runtime>(app_handle: &AppHandle<R>) -> Result<Client>
|
||||
let mut default_headers = HeaderMap::new();
|
||||
default_headers.insert("Accept", HeaderValue::from_str("application/json").unwrap());
|
||||
|
||||
let client = reqwest::ClientBuilder::new()
|
||||
let mut builder = reqwest::ClientBuilder::new()
|
||||
.timeout(Duration::from_secs(20))
|
||||
.default_headers(default_headers)
|
||||
.gzip(true)
|
||||
.user_agent(ua)
|
||||
.build()?;
|
||||
.user_agent(ua);
|
||||
|
||||
// Apply proxy settings from global app settings
|
||||
let qm = app_handle.state::<QueryManager>();
|
||||
let db = qm.inner().connect();
|
||||
let proxy = db.get_settings().proxy;
|
||||
match &proxy {
|
||||
None => { /* System default */ }
|
||||
Some(ProxySetting::Disabled) => {
|
||||
builder = builder.no_proxy();
|
||||
}
|
||||
Some(ProxySetting::Enabled { http, https, auth, bypass, disabled }) => {
|
||||
if !disabled {
|
||||
if !http.is_empty() {
|
||||
match Proxy::http(http) {
|
||||
Ok(mut p) => {
|
||||
if let Some(ProxySettingAuth { user, password }) = auth {
|
||||
debug!("Using http proxy auth");
|
||||
p = p.basic_auth(user.as_str(), password.as_str());
|
||||
}
|
||||
p = p.no_proxy(reqwest::NoProxy::from_string(bypass));
|
||||
builder = builder.proxy(p);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to apply http proxy: {e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !https.is_empty() {
|
||||
match Proxy::https(https) {
|
||||
Ok(mut p) => {
|
||||
if let Some(ProxySettingAuth { user, password }) = auth {
|
||||
debug!("Using https proxy auth");
|
||||
p = p.basic_auth(user.as_str(), password.as_str());
|
||||
}
|
||||
p = p.no_proxy(reqwest::NoProxy::from_string(bypass));
|
||||
builder = builder.proxy(p);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to apply https proxy: {e:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let client = builder.build()?;
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user