-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(updater): should use nyanpasu proxy or system proxy when performi…
…ng request (#273) * fix(updater): core updater should use nyanpasu proxy or system proxy when preforming request * fix: lint
- Loading branch information
1 parent
04cb5c4
commit dc582b4
Showing
21 changed files
with
173 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,7 +227,7 @@ impl PrfItem { | |
builder = builder.proxy(proxy); | ||
} | ||
} | ||
_ => {} | ||
_ => todo!(), | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use anyhow::Result; | ||
use sysproxy::Sysproxy; | ||
|
||
use crate::config::Config; | ||
|
||
pub fn get_self_proxy() -> Result<String> { | ||
let port = Config::verge() | ||
.latest() | ||
.verge_mixed_port | ||
.unwrap_or(Config::clash().data().get_mixed_port()); | ||
|
||
let proxy_scheme = format!("http://127.0.0.1:{port}"); | ||
Ok(proxy_scheme) | ||
} | ||
|
||
pub fn get_system_proxy() -> Result<Option<String>> { | ||
let p = Sysproxy::get_system_proxy()?; | ||
if p.enable { | ||
let proxy_scheme = format!("http://{}:{}", p.host, p.port); | ||
return Ok(Some(proxy_scheme)); | ||
} | ||
|
||
Ok(None) | ||
} | ||
|
||
pub trait NyanpasuReqwestProxyExt { | ||
fn swift_set_proxy(self, url: &str) -> Self; | ||
|
||
fn swift_set_nyanpasu_proxy(self) -> Self; | ||
} | ||
|
||
impl NyanpasuReqwestProxyExt for reqwest::ClientBuilder { | ||
fn swift_set_proxy(self, url: &str) -> Self { | ||
let mut builder = self; | ||
if let Ok(proxy) = reqwest::Proxy::http(url) { | ||
builder = builder.proxy(proxy); | ||
} | ||
if let Ok(proxy) = reqwest::Proxy::https(url) { | ||
builder = builder.proxy(proxy); | ||
} | ||
if let Ok(proxy) = reqwest::Proxy::all(url) { | ||
builder = builder.proxy(proxy); | ||
} | ||
builder | ||
} | ||
|
||
// TODO: 修改成按枚举配置 | ||
fn swift_set_nyanpasu_proxy(self) -> Self { | ||
let mut builder = self; | ||
if let Ok(proxy) = get_self_proxy() { | ||
builder = builder.swift_set_proxy(&proxy); | ||
} | ||
if let Ok(proxy) = get_system_proxy() { | ||
if let Some(proxy) = proxy { | ||
builder = builder.swift_set_proxy(&proxy); | ||
} | ||
} | ||
builder | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.