@@ -63,6 +63,12 @@ use crate::StorageConfig;
63
63
static GLOBAL_HICKORY_RESOLVER : LazyLock < Arc < HickoryResolver > > =
64
64
LazyLock :: new ( || Arc :: new ( HickoryResolver :: default ( ) ) ) ;
65
65
66
+ static GLOBAL_HTTP_CLIENT : LazyLock < HttpClient > = LazyLock :: new ( || {
67
+ new_storage_http_client ( ) . unwrap_or_else ( |err| {
68
+ panic ! ( "http client must be created successfully, but failed for {err}" )
69
+ } )
70
+ } ) ;
71
+
66
72
/// init_operator will init an opendal operator based on storage config.
67
73
pub fn init_operator ( cfg : & StorageParams ) -> Result < Operator > {
68
74
let op = match & cfg {
@@ -162,7 +168,7 @@ pub fn init_azblob_operator(cfg: &StorageAzblobConfig) -> Result<impl Builder> {
162
168
// Credential
163
169
. account_name ( & cfg. account_name )
164
170
. account_key ( & cfg. account_key )
165
- . http_client ( new_storage_http_client ( ) ? ) ;
171
+ . http_client ( GLOBAL_HTTP_CLIENT . clone ( ) ) ;
166
172
167
173
Ok ( builder)
168
174
}
@@ -187,7 +193,7 @@ fn init_gcs_operator(cfg: &StorageGcsConfig) -> Result<impl Builder> {
187
193
. bucket ( & cfg. bucket )
188
194
. root ( & cfg. root )
189
195
. credential ( & cfg. credential )
190
- . http_client ( new_storage_http_client ( ) ? ) ;
196
+ . http_client ( GLOBAL_HTTP_CLIENT . clone ( ) ) ;
191
197
192
198
Ok ( builder)
193
199
}
@@ -284,7 +290,7 @@ fn init_s3_operator(cfg: &StorageS3Config) -> Result<impl Builder> {
284
290
builder = builder. enable_virtual_host_style ( ) ;
285
291
}
286
292
287
- builder = builder. http_client ( new_storage_http_client ( ) ? ) ;
293
+ builder = builder. http_client ( GLOBAL_HTTP_CLIENT . clone ( ) ) ;
288
294
289
295
Ok ( builder)
290
296
}
@@ -301,7 +307,7 @@ fn init_obs_operator(cfg: &StorageObsConfig) -> Result<impl Builder> {
301
307
// Credential
302
308
. access_key_id ( & cfg. access_key_id )
303
309
. secret_access_key ( & cfg. secret_access_key )
304
- . http_client ( new_storage_http_client ( ) ? ) ;
310
+ . http_client ( GLOBAL_HTTP_CLIENT . clone ( ) ) ;
305
311
306
312
Ok ( builder)
307
313
}
@@ -317,7 +323,7 @@ fn init_oss_operator(cfg: &StorageOssConfig) -> Result<impl Builder> {
317
323
. root ( & cfg. root )
318
324
. server_side_encryption ( & cfg. server_side_encryption )
319
325
. server_side_encryption_key_id ( & cfg. server_side_encryption_key_id )
320
- . http_client ( new_storage_http_client ( ) ? ) ;
326
+ . http_client ( GLOBAL_HTTP_CLIENT . clone ( ) ) ;
321
327
322
328
Ok ( builder)
323
329
}
@@ -350,7 +356,7 @@ fn init_cos_operator(cfg: &StorageCosConfig) -> Result<impl Builder> {
350
356
. secret_key ( & cfg. secret_key )
351
357
. bucket ( & cfg. bucket )
352
358
. root ( & cfg. root )
353
- . http_client ( new_storage_http_client ( ) ? ) ;
359
+ . http_client ( GLOBAL_HTTP_CLIENT . clone ( ) ) ;
354
360
355
361
Ok ( builder)
356
362
}
0 commit comments