diff --git a/src/proxy.rs b/src/proxy.rs index 3b1c674..a1e2156 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -58,6 +58,12 @@ where } fn call(&mut self, req: HttpRequest) -> Self::Future { + match req.uri().path() { + "/healthz" => return Box::pin(async { Ok(Self::Response::new(HttpBody::from("OK"))) }), + "/metrics" => {} + _ => {} + }; + let target_url = self.target_url.clone(); let client = self.client.clone(); let mut inner = self.inner.clone(); @@ -86,7 +92,10 @@ where message = "received json rpc request for", method = method.method ); - if PROXY_METHODS.iter().any(|&m| method.method.starts_with(m)) { + if MULTIPLEX_METHODS + .iter() + .any(|&m| method.method.starts_with(m)) + { // let rpc server handle engine rpc requests let res = inner.call(req).await.map_err(|e| e.into())?; Ok(res) @@ -110,6 +119,7 @@ where mod tests { use std::net::SocketAddr; + use http_body_util::BodyExt; use jsonrpsee::{ core::{client::ClientT, ClientError}, http_client::HttpClient, @@ -130,6 +140,8 @@ mod tests { proxy_success().await; proxy_failure().await; does_not_proxy_engine_method().await; + does_not_proxy_eth_send_raw_transaction_method().await; + health_check().await; } async fn proxy_success() { @@ -154,6 +166,37 @@ mod tests { assert_eq!(response.unwrap(), "engine response"); } + async fn does_not_proxy_eth_send_raw_transaction_method() { + let response = send_request("eth_sendRawTransaction").await; + assert!(response.is_ok()); + assert_eq!(response.unwrap(), "raw transaction response"); + } + + async fn health_check() { + let proxy_server = spawn_proxy_server().await; + // Create a new HTTP client + let client: Client = + Client::builder(TokioExecutor::new()).build_http(); + + // Test the health check endpoint + let health_check_url = format!("http://{ADDR}:{PORT}/healthz"); + let health_response = client.get(health_check_url.parse::().unwrap()).await; + assert!(health_response.is_ok()); + let b = health_response + .unwrap() + .into_body() + .collect() + .await + .unwrap() + .to_bytes(); + // Convert the collected bytes to a string + let body_string = String::from_utf8(b.to_vec()).unwrap(); + assert_eq!(body_string, "OK"); + + proxy_server.stop().unwrap(); + proxy_server.stopped().await; + } + async fn send_request(method: &str) -> Result { let server = spawn_server().await; let proxy_server = spawn_proxy_server().await; @@ -208,6 +251,11 @@ mod tests { module .register_method("engine_method", |_, _, _| "engine response") .unwrap(); + module + .register_method("eth_sendRawTransaction", |_, _, _| { + "raw transaction response" + }) + .unwrap(); module .register_method("non_existent_method", |_, _, _| "no proxy response") .unwrap();