@@ -96,6 +96,7 @@ impl RemoteRelease {
96
96
}
97
97
98
98
pub type OnBeforeExit = Arc < dyn Fn ( ) + Send + Sync + ' static > ;
99
+ pub type OnBeforeRequest = Arc < dyn Fn ( ClientBuilder ) -> ClientBuilder + Send + Sync + ' static > ;
99
100
pub type VersionComparator = Arc < dyn Fn ( Version , RemoteRelease ) -> bool + Send + Sync > ;
100
101
type MainThreadClosure = Box < dyn FnOnce ( ) + Send + Sync + ' static > ;
101
102
type RunOnMainThread =
@@ -117,6 +118,7 @@ pub struct UpdaterBuilder {
117
118
installer_args : Vec < OsString > ,
118
119
current_exe_args : Vec < OsString > ,
119
120
on_before_exit : Option < OnBeforeExit > ,
121
+ configure_client : Option < OnBeforeRequest > ,
120
122
}
121
123
122
124
impl UpdaterBuilder {
@@ -143,6 +145,7 @@ impl UpdaterBuilder {
143
145
timeout : None ,
144
146
proxy : None ,
145
147
on_before_exit : None ,
148
+ configure_client : None ,
146
149
}
147
150
}
148
151
@@ -242,6 +245,19 @@ impl UpdaterBuilder {
242
245
self
243
246
}
244
247
248
+ /// Allows you to modify the `reqwest` client builder before the HTTP request is sent.
249
+ ///
250
+ /// Note that `reqwest` crate may be updated in minor releases of tauri-plugin-updater.
251
+ /// Therefore it's recommended to pin the plugin to at least a minor version when you're using `configure_client`.
252
+ ///
253
+ pub fn configure_client < F : Fn ( ClientBuilder ) -> ClientBuilder + Send + Sync + ' static > (
254
+ mut self ,
255
+ f : F ,
256
+ ) -> Self {
257
+ self . configure_client . replace ( Arc :: new ( f) ) ;
258
+ self
259
+ }
260
+
245
261
pub fn build ( self ) -> Result < Updater > {
246
262
let endpoints = self
247
263
. endpoints
@@ -285,6 +301,7 @@ impl UpdaterBuilder {
285
301
headers : self . headers ,
286
302
extract_path,
287
303
on_before_exit : self . on_before_exit ,
304
+ configure_client : self . configure_client ,
288
305
} )
289
306
}
290
307
}
@@ -319,6 +336,7 @@ pub struct Updater {
319
336
headers : HeaderMap ,
320
337
extract_path : PathBuf ,
321
338
on_before_exit : Option < OnBeforeExit > ,
339
+ configure_client : Option < OnBeforeRequest > ,
322
340
#[ allow( unused) ]
323
341
installer_args : Vec < OsString > ,
324
342
#[ allow( unused) ]
@@ -382,6 +400,11 @@ impl Updater {
382
400
let proxy = reqwest:: Proxy :: all ( proxy. as_str ( ) ) ?;
383
401
request = request. proxy ( proxy) ;
384
402
}
403
+
404
+ if let Some ( ref configure_client) = self . configure_client {
405
+ request = configure_client ( request) ;
406
+ }
407
+
385
408
let response = request
386
409
. build ( ) ?
387
410
. get ( url)
@@ -463,6 +486,7 @@ impl Updater {
463
486
headers : self . headers . clone ( ) ,
464
487
installer_args : self . installer_args . clone ( ) ,
465
488
current_exe_args : self . current_exe_args . clone ( ) ,
489
+ configure_client : self . configure_client . clone ( ) ,
466
490
} )
467
491
} else {
468
492
None
@@ -511,6 +535,7 @@ pub struct Update {
511
535
installer_args : Vec < OsString > ,
512
536
#[ allow( unused) ]
513
537
current_exe_args : Vec < OsString > ,
538
+ configure_client : Option < OnBeforeRequest > ,
514
539
}
515
540
516
541
impl Resource for Update { }
@@ -539,6 +564,9 @@ impl Update {
539
564
let proxy = reqwest:: Proxy :: all ( proxy. as_str ( ) ) ?;
540
565
request = request. proxy ( proxy) ;
541
566
}
567
+ if let Some ( ref configure_client) = self . configure_client {
568
+ request = configure_client ( request) ;
569
+ }
542
570
let response = request
543
571
. build ( ) ?
544
572
. get ( self . download_url . clone ( ) )
0 commit comments