@@ -25,6 +25,8 @@ pub struct Settings {
2525 auto_update : bool ,
2626 liqi_version : String ,
2727 github_token : String ,
28+ #[ serde( default ) ]
29+ req_proxy : Option < url:: Url > ,
2830 #[ serde( skip) ]
2931 methods_set : HashSet < String > ,
3032 #[ serde( skip) ]
@@ -46,6 +48,18 @@ static REQUEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
4648} ) ;
4749
4850impl Settings {
51+ fn create_github_client ( & self ) -> Result < reqwest:: Client > {
52+ let mut builder = reqwest:: Client :: builder ( ) . user_agent ( APP_USER_AGENT ) ;
53+
54+ if let Some ( req_proxy) = & self . req_proxy {
55+ let proxy = reqwest:: Proxy :: all ( req_proxy. clone ( ) )
56+ . context ( "Failed to create proxy from req_proxy" ) ?;
57+ builder = builder. proxy ( proxy) ;
58+ }
59+
60+ builder. build ( ) . context ( "Failed to build HTTP client" )
61+ }
62+
4963 pub fn new ( arg_dir : & Path ) -> Result < Self > {
5064 let exe = std:: env:: current_exe ( ) . context ( "无法获取当前可执行文件路径" ) ?;
5165 let dir = if arg_dir. is_dir ( ) {
@@ -113,14 +127,16 @@ impl Settings {
113127 ) ;
114128
115129 let resp = if self . github_token . is_empty ( ) {
116- REQUEST_CLIENT
130+ let client = self . create_github_client ( ) ?;
131+ client
117132 . get ( "https://api.github.com/repos/Xerxes-2/AutoLiqi/releases/latest" )
118133 . timeout ( std:: time:: Duration :: from_secs ( 10 ) )
119134 . send ( )
120135 . await
121136 . context ( "Failed to get latest release" ) ?
122137 } else {
123- REQUEST_CLIENT
138+ let client = self . create_github_client ( ) ?;
139+ client
124140 . get ( "https://api.github.com/repos/Xerxes-2/AutoLiqi/releases/latest" )
125141 . header ( "Authorization" , format ! ( "Bearer {}" , self . github_token) )
126142 . header ( "X-GitHub-Api-Version" , "2022-11-28" )
@@ -167,14 +183,16 @@ impl Settings {
167183 . as_str ( )
168184 . context ( "No download url found in asset" ) ?;
169185 let resp = if self . github_token . is_empty ( ) {
170- REQUEST_CLIENT
186+ let client = self . create_github_client ( ) ?;
187+ client
171188 . get ( url)
172189 . timeout ( std:: time:: Duration :: from_secs ( 10 ) )
173190 . send ( )
174191 . await
175192 . context ( "Failed to download asset" ) ?
176193 } else {
177- REQUEST_CLIENT
194+ let client = self . create_github_client ( ) ?;
195+ client
178196 . get ( url)
179197 . header ( "Authorization" , format ! ( "Bearer {}" , self . github_token) )
180198 . header ( "X-GitHub-Api-Version" , "2022-11-28" )
0 commit comments