mirror of
https://github.com/anomalyco/opencode.git
synced 2026-04-24 23:04:55 +00:00
cleanup
This commit is contained in:
@@ -198,32 +198,37 @@ fn spawn_sidecar(app: &AppHandle, port: u32, password: &str) -> CommandChild {
|
|||||||
child
|
child
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn check_server_health(url: &str, password: Option<&str>) -> bool {
|
fn url_is_localhost(url: &reqwest::Url) -> bool {
|
||||||
let health_url = format!("{}/global/health", url.trim_end_matches('/'));
|
url.host_str().is_some_and(|host| {
|
||||||
|
host.eq_ignore_ascii_case("localhost")
|
||||||
|
|| host
|
||||||
|
.parse::<std::net::IpAddr>()
|
||||||
|
.is_ok_and(|ip| ip.is_loopback())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Some environments set proxy variables (HTTP_PROXY/HTTPS_PROXY/ALL_PROXY) without
|
async fn check_server_health(url: &str, password: Option<&str>) -> bool {
|
||||||
// excluding loopback. reqwest respects these by default, which can prevent the desktop
|
let Ok(url) = reqwest::Url::parse(url) else {
|
||||||
// app from reaching its own local sidecar server.
|
return false;
|
||||||
let no_proxy = reqwest::Url::parse(&health_url).ok().is_some_and(|u| {
|
};
|
||||||
u.host_str().is_some_and(|host| {
|
|
||||||
host.eq_ignore_ascii_case("localhost")
|
|
||||||
|| host
|
|
||||||
.parse::<std::net::IpAddr>()
|
|
||||||
.is_ok_and(|ip| ip.is_loopback())
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
let mut builder = reqwest::Client::builder().timeout(Duration::from_secs(3));
|
let mut builder = reqwest::Client::builder().timeout(Duration::from_secs(3));
|
||||||
|
|
||||||
if no_proxy {
|
if url_is_localhost(&url) {
|
||||||
|
// Some environments set proxy variables (HTTP_PROXY/HTTPS_PROXY/ALL_PROXY) without
|
||||||
|
// excluding loopback. reqwest respects these by default, which can prevent the desktop
|
||||||
|
// app from reaching its own local sidecar server.
|
||||||
builder = builder.no_proxy();
|
builder = builder.no_proxy();
|
||||||
};
|
};
|
||||||
|
|
||||||
let Ok(client) = builder.build() else {
|
let Ok(client) = builder.build() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
let Ok(health_url) = url.join("/global/health") else {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
let mut req = client.get(&health_url);
|
let mut req = client.get(health_url);
|
||||||
|
|
||||||
if let Some(password) = password {
|
if let Some(password) = password {
|
||||||
req = req.basic_auth("opencode", Some(password));
|
req = req.basic_auth("opencode", Some(password));
|
||||||
|
|||||||
Reference in New Issue
Block a user