@@ -16,7 +16,7 @@ use http::HeaderName;
1616use minisign_verify:: { PublicKey , Signature } ;
1717use reqwest:: {
1818 header:: { HeaderMap , HeaderValue } ,
19- Client , StatusCode ,
19+ ClientBuilder , StatusCode ,
2020} ;
2121use semver:: Version ;
2222use serde:: { de:: Error as DeError , Deserialize , Deserializer , Serialize } ;
@@ -94,6 +94,7 @@ pub struct UpdaterBuilder {
9494 endpoints : Option < Vec < Url > > ,
9595 headers : HeaderMap ,
9696 timeout : Option < Duration > ,
97+ proxy : Option < Url > ,
9798 installer_args : Option < Vec < String > > ,
9899}
99100
@@ -113,6 +114,7 @@ impl UpdaterBuilder {
113114 endpoints : None ,
114115 headers : Default :: default ( ) ,
115116 timeout : None ,
117+ proxy : None ,
116118 installer_args : None ,
117119 }
118120 }
@@ -160,6 +162,11 @@ impl UpdaterBuilder {
160162 self
161163 }
162164
165+ pub fn proxy ( mut self , proxy : Url ) -> Self {
166+ self . proxy . replace ( proxy) ;
167+ self
168+ }
169+
163170 pub fn installer_args < I , S > ( mut self , args : I ) -> Self
164171 where
165172 I : IntoIterator < Item = S > ,
@@ -201,6 +208,7 @@ impl UpdaterBuilder {
201208 current_version : self . current_version ,
202209 version_comparator : self . version_comparator ,
203210 timeout : self . timeout ,
211+ proxy : self . proxy ,
204212 endpoints,
205213 installer_args : self . installer_args . unwrap_or ( self . config . installer_args ) ,
206214 arch,
@@ -217,6 +225,7 @@ pub struct Updater {
217225 current_version : Version ,
218226 version_comparator : Option < Box < dyn Fn ( Version , RemoteRelease ) -> bool + Send + Sync > > ,
219227 timeout : Option < Duration > ,
228+ proxy : Option < Url > ,
220229 endpoints : Vec < Url > ,
221230 #[ allow( dead_code) ]
222231 installer_args : Vec < String > ,
@@ -271,11 +280,20 @@ impl Updater {
271280 . replace ( "{{arch}}" , self . arch )
272281 . parse ( ) ?;
273282
274- let mut request = Client :: new ( ) . get ( url ) . headers ( headers . clone ( ) ) ;
283+ let mut request = ClientBuilder :: new ( ) ;
275284 if let Some ( timeout) = self . timeout {
276285 request = request. timeout ( timeout) ;
277286 }
278- let response = request. send ( ) . await ;
287+ if let Some ( ref proxy) = self . proxy {
288+ let proxy = reqwest:: Proxy :: all ( proxy. as_str ( ) ) ?;
289+ request = request. proxy ( proxy) ;
290+ }
291+ let response = request
292+ . build ( ) ?
293+ . get ( url)
294+ . headers ( headers. clone ( ) )
295+ . send ( )
296+ . await ;
279297
280298 if let Ok ( res) = response {
281299 if res. status ( ) . is_success ( ) {
@@ -326,6 +344,7 @@ impl Updater {
326344 body : release. notes . clone ( ) ,
327345 signature : release. signature ( & self . json_target ) ?. to_owned ( ) ,
328346 timeout : self . timeout ,
347+ proxy : self . proxy . clone ( ) ,
329348 headers : self . headers . clone ( ) ,
330349 } )
331350 } else {
@@ -360,6 +379,8 @@ pub struct Update {
360379 pub signature : String ,
361380 /// Request timeout
362381 pub timeout : Option < Duration > ,
382+ /// Request proxy
383+ pub proxy : Option < Url > ,
363384 /// Request headers
364385 pub headers : HeaderMap ,
365386}
@@ -384,13 +405,20 @@ impl Update {
384405 HeaderValue :: from_str ( "tauri-updater" ) . unwrap ( ) ,
385406 ) ;
386407
387- let mut request = Client :: new ( )
388- . get ( self . download_url . clone ( ) )
389- . headers ( headers) ;
408+ let mut request = ClientBuilder :: new ( ) ;
390409 if let Some ( timeout) = self . timeout {
391410 request = request. timeout ( timeout) ;
392411 }
393- let response = request. send ( ) . await ?;
412+ if let Some ( ref proxy) = self . proxy {
413+ let proxy = reqwest:: Proxy :: all ( proxy. as_str ( ) ) ?;
414+ request = request. proxy ( proxy) ;
415+ }
416+ let response = request
417+ . build ( ) ?
418+ . get ( self . download_url . clone ( ) )
419+ . headers ( headers)
420+ . send ( )
421+ . await ?;
394422
395423 if !response. status ( ) . is_success ( ) {
396424 return Err ( Error :: Network ( format ! (
0 commit comments