@@ -99,6 +99,14 @@ macro_rules! jsonrpc {
9999 $struct_name { id: 0 . into( ) , client: $crate:: rpc:: RpcClient :: new_with_cookie( uri) , }
100100 }
101101
102+ pub fn with_builder<F >( uri: & str , f: F ) -> Result <Self , anyhow:: Error >
103+ where
104+ F : FnOnce ( reqwest:: ClientBuilder ) -> reqwest:: ClientBuilder ,
105+ {
106+ let client = $crate:: rpc:: RpcClient :: with_builder( uri, f) ?;
107+ Ok ( $struct_name { id: 0 . into( ) , client } )
108+ }
109+
102110 pub fn post<PARAM , RET >( & self , method: & str , params: PARAM ) ->Result <RET , $crate:: rpc:: RpcError >
103111 where
104112 PARAM : serde:: ser:: Serialize + Send + ' static ,
@@ -178,6 +186,15 @@ macro_rules! jsonrpc_async {
178186 pub fn new_with_cookie( uri: & str ) -> Self {
179187 $struct_name { id: 0 . into( ) , client: $crate:: rpc:: RpcClient :: new_with_cookie( uri) , }
180188 }
189+
190+ pub fn with_builder<F >( uri: & str , f: F ) -> Result <Self , anyhow:: Error >
191+ where
192+ F : FnOnce ( reqwest:: ClientBuilder ) -> reqwest:: ClientBuilder ,
193+ {
194+ let client = $crate:: rpc:: RpcClient :: with_builder( uri, f) ?;
195+ Ok ( $struct_name { id: 0 . into( ) , client } )
196+ }
197+
181198 #[ cfg( not( target_arch="wasm32" ) ) ]
182199 pub fn post<PARAM , RET >( & self , method: & str , params: PARAM ) ->impl std:: future:: Future <Output =Result <RET , $crate:: rpc:: RpcError >> + Send + ' static
183200 where
@@ -260,6 +277,17 @@ impl RpcClient {
260277 }
261278 }
262279
280+ pub fn with_builder < F > ( uri : & str , f : F ) -> Result < Self , anyhow:: Error >
281+ where
282+ F : FnOnce ( reqwest:: ClientBuilder ) -> reqwest:: ClientBuilder ,
283+ {
284+ let url = reqwest:: Url :: parse ( uri) ?;
285+ let client = f ( reqwest:: Client :: builder ( ) )
286+ . build ( )
287+ . map_err ( |e| anyhow:: anyhow!( "Failed to build HTTP client: {}" , e) ) ?;
288+ Ok ( Self { client, url } )
289+ }
290+
263291 #[ cfg( not( target_arch = "wasm32" ) ) ]
264292 pub fn new_with_cookie ( uri : & str ) -> Self {
265293 let url = reqwest:: Url :: parse ( uri) . expect ( "ckb uri, e.g. \" http://127.0.0.1:8114\" " ) ;
0 commit comments