Open Skimige opened 2 weeks ago
i think i will ship the database with future releases. the local db pr hasn't been merged yet because i haven't gotten around to testing it
Inspired by @Skimige , I searched for "ureq proxy" and found this. It mentions that
I see that wasm-pack and binary-install all calls
ureq::get(..)
to download, which initializes an agent with the default settingAgentBuilder::new().build()
, and by defaulttry_proxy_from_env
ofAgentBuilder
is set tofalse
, so it ended up not using the proxy environment variables.
I studied the Rust documentation and tried to modify get()
so that it can use the proxy from the HTTP_HOSTS environment variable.
fn get<T: DeserializeOwned>(url: String) -> T {
debug!(url, "requesting from resource");
ureq::AgentBuilder::new().try_proxy_from_env(true).build()
.get(&url)
.call()
.unwrap()
.into_json()
.unwrap()
}
I'm glad it works well.
However, I use an app which controls the 'manual proxy setup' settings in Windows, and it uses the registry. So I studied it further and modified get()
to use the proxy configured in the registry keys.
fn get<T: DeserializeOwned>(url: String) -> T {
debug!(url, "requesting from resource");
// Open registry key.
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
let internet_settings = hkcu.open_subkey_with_flags(
"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
KEY_READ,
).unwrap();
// Read Proxy Settings.
let proxy_enable: u32 = internet_settings.get_value("ProxyEnable").unwrap();
let proxy_server: String = internet_settings.get_value("ProxyServer").unwrap();
if proxy_enable == 0 {
ureq::get(&url)
.call()
.unwrap()
.into_json()
.unwrap()
} else {
ureq::AgentBuilder::new()
.proxy(ureq::Proxy::new(proxy_server).unwrap())
.build()
.get(&url)
.call()
.unwrap()
.into_json()
.unwrap()
}
}
Without a proxy, it's only 4KB/s when updating Database. But now I can have a normal download speed. ^ ^
Of course, modifying get()
directly is not very elegant. Perhaps the logic for creating agent
could be moved to a new struct or main.rs
, and then agent
could be passed to Database
for use.
This issue looks like a duplicate of #13, lol.
I am experiencing difficulty connecting to
raw.githubusercontent.com
from my home network. Despite setting thehttp_proxy
andall_proxy
environment variables, the connection does not work, and I cannot see any log entries from my proxy.Based on my research,
ureq
should automatically support proxy environments, but this doesn't seem to be the case here.As a workaround, I replaced the link with a mirror (built using actions in a private fork), and it worked.
Given that a local database is not the preferred solution (#11), is there any possibility of implementing proxy support for database fetching?
Thank you for developing this tool!