@@ -2168,11 +2168,14 @@ pub fn init_test_services(
2168
2168
/// Holds functionality for remote use of the [`ReadStateService`] ([`RemoteStateService`]).
2169
2169
#[ cfg( feature = "remote_read_state_service" ) ]
2170
2170
pub mod remote {
2171
+ use std:: fs;
2172
+
2171
2173
use super :: * ;
2172
2174
2175
+ use http:: header:: COOKIE ;
2173
2176
use jsonrpsee:: {
2174
2177
core:: client:: ClientT ,
2175
- http_client:: { HttpClient , HttpClientBuilder } ,
2178
+ http_client:: { HeaderMap , HttpClient , HttpClientBuilder } ,
2176
2179
} ;
2177
2180
use url:: Url ;
2178
2181
@@ -2199,16 +2202,28 @@ pub mod remote {
2199
2202
}
2200
2203
2201
2204
impl RemoteStateService {
2202
- /// Creates a new remote, read-only state service client.
2205
+ /// Creates a new remote, read-only state service client with optional cookie authentication .
2203
2206
#[ allow( dead_code) ]
2204
- pub fn new ( url : Url ) -> Result < Self , BoxError > {
2205
- let client = HttpClientBuilder :: default ( )
2206
- . request_timeout ( Duration :: from_secs ( 5 ) )
2207
- . build ( url. as_str ( ) ) ?;
2208
-
2209
- let remote_read_state_service = Self { client } ;
2207
+ pub fn new ( url : Url , cookie : Option < String > ) -> Result < Self , BoxError > {
2208
+ let mut builder = HttpClientBuilder :: default ( ) . request_timeout ( Duration :: from_secs ( 5 ) ) ;
2209
+
2210
+ if let Some ( cookie_path) = cookie {
2211
+ let cookie_content =
2212
+ fs:: read_to_string ( & cookie_path) . map_err ( |e| Box :: new ( e) as BoxError ) ?;
2213
+ let cookie_content = cookie_content. trim ( ) ;
2214
+
2215
+ let mut headers = HeaderMap :: new ( ) ;
2216
+ headers. insert (
2217
+ COOKIE ,
2218
+ cookie_content
2219
+ . parse ( )
2220
+ . map_err ( |e| Box :: new ( e) as BoxError ) ?,
2221
+ ) ;
2222
+ builder = builder. set_headers ( headers) ;
2223
+ }
2210
2224
2211
- Ok ( remote_read_state_service)
2225
+ let client = builder. build ( url. as_str ( ) ) ?;
2226
+ Ok ( Self { client } )
2212
2227
}
2213
2228
2214
2229
/// Sends a request to the server an waits on a response.
0 commit comments