@@ -10,6 +10,8 @@ use gleam_core::{
10
10
use http:: { Request , Response } ;
11
11
use reqwest:: { Certificate , Client } ;
12
12
13
+ use crate :: fs;
14
+
13
15
static REQWEST_CLIENT : OnceLock < Client > = OnceLock :: new ( ) ;
14
16
15
17
#[ derive( Debug ) ]
@@ -50,20 +52,18 @@ fn init_client() -> Result<&'static Client, Error> {
50
52
return Ok ( client) ;
51
53
}
52
54
53
- let certificate_path = std:: env:: var ( "GLEAM_CACERTS_PATH" ) . map_err ( |error| Error :: FileIo {
54
- kind : FileKind :: Directory ,
55
- action : FileIoAction :: Read ,
56
- path : Utf8PathBuf :: new ( ) ,
57
- err : Some ( error. to_string ( ) ) ,
58
- } ) ?;
59
-
60
- let certificate_bytes = std:: fs:: read ( & certificate_path) . map_err ( |error| Error :: FileIo {
61
- kind : FileKind :: File ,
62
- action : FileIoAction :: Parse ,
63
- path : Utf8PathBuf :: from ( & certificate_path) ,
64
- err : Some ( error. to_string ( ) ) ,
65
- } ) ?;
55
+ let certificate_path = match std:: env:: var ( "GLEAM_CACERTS_PATH" ) {
56
+ Ok ( path) => path,
57
+ Err ( _) => {
58
+ return Ok ( REQWEST_CLIENT . get_or_init ( || {
59
+ Client :: builder ( )
60
+ . build ( )
61
+ . expect ( "Failed to create reqwest client" )
62
+ } ) ) ;
63
+ }
64
+ } ;
66
65
66
+ let certificate_bytes = fs:: read_bytes ( & certificate_path) ?;
67
67
let certificate = Certificate :: from_pem ( & certificate_bytes) . map_err ( |error| Error :: FileIo {
68
68
kind : FileKind :: File ,
69
69
action : FileIoAction :: Parse ,
0 commit comments