@@ -20,7 +20,7 @@ const BANDIT_ENDPOINT: &'static str = "/flag-config/v1/bandits";
20
20
/// A client that fetches Eppo configuration from the server.
21
21
pub struct ConfigurationFetcher {
22
22
// Client holds a connection pool internally, so we're reusing the client between requests.
23
- client : reqwest:: blocking :: Client ,
23
+ client : reqwest:: Client ,
24
24
config : ConfigurationFetcherConfig ,
25
25
/// If we receive a 401 Unauthorized error during a request, it means the API key is not
26
26
/// valid. We cache this error so we don't issue additional requests to the server.
@@ -29,7 +29,7 @@ pub struct ConfigurationFetcher {
29
29
30
30
impl ConfigurationFetcher {
31
31
pub fn new ( config : ConfigurationFetcherConfig ) -> ConfigurationFetcher {
32
- let client = reqwest:: blocking :: Client :: new ( ) ;
32
+ let client = reqwest:: Client :: new ( ) ;
33
33
34
34
ConfigurationFetcher {
35
35
client,
@@ -38,24 +38,24 @@ impl ConfigurationFetcher {
38
38
}
39
39
}
40
40
41
- pub fn fetch_configuration ( & mut self ) -> Result < Configuration > {
41
+ pub async fn fetch_configuration ( & mut self ) -> Result < Configuration > {
42
42
if self . unauthorized {
43
43
return Err ( Error :: Unauthorized ) ;
44
44
}
45
45
46
- let ufc = self . fetch_ufc_configuration ( ) ?;
46
+ let ufc = self . fetch_ufc_configuration ( ) . await ?;
47
47
48
48
let bandits = if ufc. compiled . flag_to_bandit_associations . is_empty ( ) {
49
49
// We don't need bandits configuration if there are no bandits.
50
50
None
51
51
} else {
52
- Some ( self . fetch_bandits_configuration ( ) ?)
52
+ Some ( self . fetch_bandits_configuration ( ) . await ?)
53
53
} ;
54
54
55
55
Ok ( Configuration :: from_server_response ( ufc, bandits) )
56
56
}
57
57
58
- fn fetch_ufc_configuration ( & mut self ) -> Result < UniversalFlagConfig > {
58
+ async fn fetch_ufc_configuration ( & mut self ) -> Result < UniversalFlagConfig > {
59
59
let url = Url :: parse_with_params (
60
60
& format ! ( "{}{}" , self . config. base_url, UFC_ENDPOINT ) ,
61
61
& [
@@ -68,7 +68,7 @@ impl ConfigurationFetcher {
68
68
. map_err ( |err| Error :: InvalidBaseUrl ( err) ) ?;
69
69
70
70
log:: debug!( target: "eppo" , "fetching UFC flags configuration" ) ;
71
- let response = self . client . get ( url) . send ( ) ?;
71
+ let response = self . client . get ( url) . send ( ) . await ?;
72
72
73
73
let response = response. error_for_status ( ) . map_err ( |err| {
74
74
if err. status ( ) == Some ( StatusCode :: UNAUTHORIZED ) {
@@ -82,15 +82,17 @@ impl ConfigurationFetcher {
82
82
}
83
83
} ) ?;
84
84
85
- let configuration =
86
- UniversalFlagConfig :: from_json ( self . config . sdk_metadata , response. bytes ( ) ?. into ( ) ) ?;
85
+ let configuration = UniversalFlagConfig :: from_json (
86
+ self . config . sdk_metadata ,
87
+ response. bytes ( ) . await ?. into ( ) ,
88
+ ) ?;
87
89
88
90
log:: debug!( target: "eppo" , "successfully fetched UFC flags configuration" ) ;
89
91
90
92
Ok ( configuration)
91
93
}
92
94
93
- fn fetch_bandits_configuration ( & mut self ) -> Result < BanditResponse > {
95
+ async fn fetch_bandits_configuration ( & mut self ) -> Result < BanditResponse > {
94
96
let url = Url :: parse_with_params (
95
97
& format ! ( "{}{}" , self . config. base_url, BANDIT_ENDPOINT ) ,
96
98
& [
@@ -103,7 +105,7 @@ impl ConfigurationFetcher {
103
105
. map_err ( |err| Error :: InvalidBaseUrl ( err) ) ?;
104
106
105
107
log:: debug!( target: "eppo" , "fetching UFC bandits configuration" ) ;
106
- let response = self . client . get ( url) . send ( ) ?;
108
+ let response = self . client . get ( url) . send ( ) . await ?;
107
109
108
110
let response = response. error_for_status ( ) . map_err ( |err| {
109
111
if err. status ( ) == Some ( StatusCode :: UNAUTHORIZED ) {
@@ -117,7 +119,7 @@ impl ConfigurationFetcher {
117
119
}
118
120
} ) ?;
119
121
120
- let configuration = response. json ( ) ?;
122
+ let configuration = response. json ( ) . await ?;
121
123
122
124
log:: debug!( target: "eppo" , "successfully fetched UFC bandits configuration" ) ;
123
125
0 commit comments