58
58
}
59
59
60
60
fn call ( & mut self , req : HttpRequest < HttpBody > ) -> Self :: Future {
61
+ match req. uri ( ) . path ( ) {
62
+ "/healthz" => return Box :: pin ( async { Ok ( Self :: Response :: new ( HttpBody :: from ( "OK" ) ) ) } ) ,
63
+ "/metrics" => { }
64
+ _ => { }
65
+ } ;
66
+
61
67
let target_url = self . target_url . clone ( ) ;
62
68
let client = self . client . clone ( ) ;
63
69
let mut inner = self . inner . clone ( ) ;
86
92
message = "received json rpc request for" ,
87
93
method = method. method
88
94
) ;
89
- if PROXY_METHODS . iter ( ) . any ( |& m| method. method . starts_with ( m) ) {
95
+ if MULTIPLEX_METHODS
96
+ . iter ( )
97
+ . any ( |& m| method. method . starts_with ( m) )
98
+ {
90
99
// let rpc server handle engine rpc requests
91
100
let res = inner. call ( req) . await . map_err ( |e| e. into ( ) ) ?;
92
101
Ok ( res)
@@ -110,6 +119,7 @@ where
110
119
mod tests {
111
120
use std:: net:: SocketAddr ;
112
121
122
+ use http_body_util:: BodyExt ;
113
123
use jsonrpsee:: {
114
124
core:: { client:: ClientT , ClientError } ,
115
125
http_client:: HttpClient ,
@@ -130,6 +140,8 @@ mod tests {
130
140
proxy_success ( ) . await ;
131
141
proxy_failure ( ) . await ;
132
142
does_not_proxy_engine_method ( ) . await ;
143
+ does_not_proxy_eth_send_raw_transaction_method ( ) . await ;
144
+ health_check ( ) . await ;
133
145
}
134
146
135
147
async fn proxy_success ( ) {
@@ -154,6 +166,37 @@ mod tests {
154
166
assert_eq ! ( response. unwrap( ) , "engine response" ) ;
155
167
}
156
168
169
+ async fn does_not_proxy_eth_send_raw_transaction_method ( ) {
170
+ let response = send_request ( "eth_sendRawTransaction" ) . await ;
171
+ assert ! ( response. is_ok( ) ) ;
172
+ assert_eq ! ( response. unwrap( ) , "raw transaction response" ) ;
173
+ }
174
+
175
+ async fn health_check ( ) {
176
+ let proxy_server = spawn_proxy_server ( ) . await ;
177
+ // Create a new HTTP client
178
+ let client: Client < HttpConnector , HttpBody > =
179
+ Client :: builder ( TokioExecutor :: new ( ) ) . build_http ( ) ;
180
+
181
+ // Test the health check endpoint
182
+ let health_check_url = format ! ( "http://{ADDR}:{PORT}/healthz" ) ;
183
+ let health_response = client. get ( health_check_url. parse :: < Uri > ( ) . unwrap ( ) ) . await ;
184
+ assert ! ( health_response. is_ok( ) ) ;
185
+ let b = health_response
186
+ . unwrap ( )
187
+ . into_body ( )
188
+ . collect ( )
189
+ . await
190
+ . unwrap ( )
191
+ . to_bytes ( ) ;
192
+ // Convert the collected bytes to a string
193
+ let body_string = String :: from_utf8 ( b. to_vec ( ) ) . unwrap ( ) ;
194
+ assert_eq ! ( body_string, "OK" ) ;
195
+
196
+ proxy_server. stop ( ) . unwrap ( ) ;
197
+ proxy_server. stopped ( ) . await ;
198
+ }
199
+
157
200
async fn send_request ( method : & str ) -> Result < String , ClientError > {
158
201
let server = spawn_server ( ) . await ;
159
202
let proxy_server = spawn_proxy_server ( ) . await ;
@@ -208,6 +251,11 @@ mod tests {
208
251
module
209
252
. register_method ( "engine_method" , |_, _, _| "engine response" )
210
253
. unwrap ( ) ;
254
+ module
255
+ . register_method ( "eth_sendRawTransaction" , |_, _, _| {
256
+ "raw transaction response"
257
+ } )
258
+ . unwrap ( ) ;
211
259
module
212
260
. register_method ( "non_existent_method" , |_, _, _| "no proxy response" )
213
261
. unwrap ( ) ;
0 commit comments