@@ -16,10 +16,20 @@ pub enum Error {
1616}
1717
1818pub struct Client {
19- pub ( crate ) endpoint : String ,
19+ endpoint : String ,
20+ client : reqwest:: Client ,
2021}
2122
2223impl Client {
24+ pub ( crate ) fn new (
25+ endpoint : impl Into < String > ,
26+ builder : reqwest:: ClientBuilder ,
27+ ) -> Result < Self , reqwest:: Error > {
28+ let client = builder. build ( ) ?;
29+ let endpoint = endpoint. into ( ) ;
30+ Ok ( Client { endpoint, client } )
31+ }
32+
2333 pub async fn get ( & self , key : & str ) -> Result < Option < Vec < u8 > > , Error > {
2434 do_get ( self , key) . await
2535 }
@@ -41,7 +51,12 @@ async fn do_get(client: &Client, key: &str) -> Result<Option<Vec<u8>>, Error> {
4151
4252 url = url. join ( & encoded_key) . change_context_lazy ( make_error) ?;
4353
44- let resp = reqwest:: get ( url) . await . change_context_lazy ( make_error) ?;
54+ let resp = client
55+ . client
56+ . get ( url)
57+ . send ( )
58+ . await
59+ . change_context_lazy ( make_error) ?;
4560
4661 match resp. status ( ) {
4762 StatusCode :: OK => {
@@ -63,7 +78,8 @@ async fn do_put(client: &Client, key: &str, value: &[u8]) -> Result<(), Error> {
6378
6479 url = url. join ( & encoded_key) . change_context_lazy ( make_error) ?;
6580
66- let resp = reqwest:: Client :: new ( )
81+ let resp = client
82+ . client
6783 . put ( url)
6884 . body ( value. to_vec ( ) )
6985 . send ( )
@@ -85,7 +101,8 @@ async fn do_delete(client: &Client, key: &str) -> Result<(), Error> {
85101
86102 url = url. join ( & encoded_key) . change_context_lazy ( make_error) ?;
87103
88- let resp = reqwest:: Client :: new ( )
104+ let resp = client
105+ . client
89106 . delete ( url)
90107 . send ( )
91108 . await
0 commit comments